【发布时间】:2014-02-24 21:58:48
【问题描述】:
使用 MVVM 模式,我已将组合框的 SelectedIndex 属性绑定到我的视图模型中的变量。我可以从视图模型中以编程方式更改组合框选择;但是,当用户从界面(视图)中进行选择时,视图模型变量不会更新。
这是 XAML(片段):
<ComboBox Width="100"
HorizontalContentAlignment="Center"
SelectedIndex="{Binding GroupSortIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Content="Appearance"/>
<ComboBoxItem Content="Created"/>
<ComboBoxItem Content="Name"/>
</ComboBox>
这是视图模型的一部分:
public int GroupSortIndex
{
get { return (int)GetValue(GroupSortIndexProperty); }
set { SetValue(GroupSortIndexProperty, value); }
}
public static readonly DependencyProperty GroupSortIndexProperty =
DependencyProperty.Register("GroupSortIndex", typeof(int),
typeof(MainWindowViewModel), new UIPropertyMetadata(-1));
当用户从 IU 中进行选择时,我需要做什么来更新 GroupSortIndex?
【问题讨论】: