【发布时间】:2020-05-21 08:56:56
【问题描述】:
我在 WPF MVVM 中有一个组合框,我在组合框中有 3 个值。值是:A-B-全部 我想“全部”是组合框中的默认选择,我该怎么做?
我的 xaml 中的组合框:
<ComboBox ItemsSource="{Binding Locations}" SelectedItem ="{Binding SelectedLocation}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding LocationFilterCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
我的视图模型中的位置可观察集合:
private ObservableCollection<string> _locations;
public ObservableCollection<string> Locations
{
get { return _locations; }
set
{
_locations = value;
OnPropertyChanged("Locations");
}
}
Locations = new ObservableCollection<string>()
{
"All","A","B"
};
感谢您的所有帮助。
【问题讨论】:
-
将默认值设置为
SelectedLocation