Mvvm 自动完成盒Don';t按向下/向上键选择编辑项

Mvvm 自动完成盒Don';t按向下/向上键选择编辑项,mvvm,autocomplete,selecteditem,Mvvm,Autocomplete,Selecteditem,我在MVVM中使用AutoCompleteBox,我只想在用户单击该项或按Enter键时执行某些操作 但现在,当我使用键盘上的向下\向上键时,selectedItem属性会更改 我的控制: <Controls:AutoCompleteBox ItemsSource="{Binding IndicationDtos, Mode=TwoWay}" Width="100" SelectedItem="{Binding Indicati

我在MVVM中使用AutoCompleteBox,我只想在用户单击该项或按Enter键时执行某些操作

但现在,当我使用键盘上的向下\向上键时,selectedItem属性会更改

我的控制:

<Controls:AutoCompleteBox ItemsSource="{Binding IndicationDtos, Mode=TwoWay}" 
                              Width="100" SelectedItem="{Binding IndicationSelected, Mode=TwoWay}" 
                              ValueMemberPath="Diagnosis" Text="{Binding Criteria, Mode=TwoWay}" MinimumPopulateDelay="250"/>

如何使属性“SelectedItem”仅在输入或单击时分配

如果你有任何问题


非常感谢在SelectedItem绑定中,您可以使用:

SelectedItem="{Binding IndicationSelected, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"  

这样,只有当您关注其他内容时,所选项目才会发生变化。

我找到了解决方案,创建了一个新类

像这样:

    public class AutoCompleteBoxEx : AutoCompleteBox
{
            public static readonly DependencyProperty SelectionBoxItemProperty =
        DependencyProperty.Register(
        "SelectionBoxItem",
        typeof(object),
        typeof(AutoCompleteBox),
        new PropertyMetadata(OnSelectionBoxItemPropertyChanged));

    public object SelectionBoxItem
    {
        get
        {
            return GetValue(SelectionBoxItemProperty);
        }

        set
        {
            SetValue(SelectionBoxItemProperty, value);
        }
    }

    protected override void OnDropDownClosing(RoutedPropertyChangingEventArgs<bool> e)
    {
        base.OnDropDownClosing(e);
        SelectionBoxItem = SelectionAdapter.SelectedItem;
    }

    private static void OnSelectionBoxItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
    }
}
公共类AutoCompleteBox:AutoCompleteBox
{
公共静态只读从属属性SelectionBoxItemProperty=
从属属性。寄存器(
“SelectionBoxItem”,
类型(对象),
类型(自动完成框),
新属性元数据(OnSelectionBoxItemPropertyChanged);
公共对象选择框项
{
得到
{
返回GetValue(SelectionBoxItemProperty);
}
设置
{
SetValue(SelectionBoxItemProperty,value);
}
}
受保护的覆盖无效OnDropDownClosing(RoutedPropertyChangingEventArgs e)
{
基地。关闭(e);
SelectionBoxItem=SelectionAdapter.SelectedItem;
}
SelectionBoxItemPropertyChanged上的私有静态无效(DependencyObject d、DependencyPropertyChangedEventArgs e)
{
}
}

Thx,但我没有更新SourceTrigger=LostFocus,我与Silverlight合作就是为了这个?其他想法?啊,不,对于silverlight,您需要一些移动自定义的东西。看到这一点:我无法理解如何使用LostFocus解决我的问题?这将延迟您所选项目的更改,直到您单击其他位置。