我想在此ComboBox中设置默认值。 ItemsSource包含两个元素。我希望当我打开包含我的组合框的窗口时,第二个元素是默认元素。这是代码。
XAML:
<ComboBox Grid.Row="2" Name="_cmbServiceType" Visibility="Visible"
SelectedValue="{Binding Path=FL_TYPE, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=true}"
ItemsSource="{Binding Path= ClientList}"
SelectedValuePath="FL_TYPE"
DisplayMemberPath="ID_TYPE"
SelectedItem="{Binding Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"/>
视图模型:
private ObservableCollection<GenericEnumType<string>> _clientList = null;
public ObservableCollection<GenericEnumType<string>> ClientList
{
get
{
Master.Controller.Execute(delegate(IResult result)
{
_clientList = new ObservableCollection<GenericEnumType<string>>()
{
new GenericEnumType<string>(SAPClient.WEBSERVICE_URL_500.ToString(), CappTranslate.Translate.EBOM),
new GenericEnumType<string>(SAPClient.WEBSERVICE_URL_400.ToString(), CappTranslate.Translate.PBOM),
};
return true;
});
return _clientList;
}
}
private GenericEnumType<string> _selectedItem = null;
public GenericEnumType<string> SelectedItem
{
get { return _selectedItem; }
set
{
_selectedItem = value;
if (_selectedItem.FL_TYPE == SAPClient.WEBSERVICE_URL_500.ToString())
_selectedBomUsage = null;
OnPropertyChanged(() => SelectedItem);
OnPropertyChanged(() => CanClose);
OnPropertyChanged(() => IsComboUsageEnabled);
OnPropertyChanged(() => SelectedBomUsage);
}
}
我尝试在My Constructor中设置:
SelectedItem = ClientList[1];
但它不起作用。
一些建议??
答案 0 :(得分:0)
我说,你不应该同时设置SelectedValue和SelectedItem。
尝试设置SelectedItem。