如何在ComboBox多列中设置默认值? [英] How can I set the default values in a ComboBox multicolumns ?
本文介绍了如何在ComboBox多列中设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多列组合框。在组合人口之后,我尝试设置默认值,但是我收到错误消息
这是我的代码
I have a multi columns combobox. After combo population, I try to set the default values, but I get an error message
This is my codes
public ObservableCollection<Model_Sedi> Sedi { get; set; }
private Model_Sedi _Sedi_Search;
public Model_Sedi Sedi_Search {
get { return _Sedi_Search; }
set {
_Sedi_Search = value;
OnPropertyChanged("Sedi_Search");
}
}
<ComboBox x:Name="Cmb_Sede"
ItemsSource="{Binding Sedi, Mode=TwoWay}"
SelectedValuePath="Value"
SelectedItem="{Binding Sedi_Search, Mode=TwoWay}"
VerticalAlignment="Top" Width="189">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding IdSede, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
<TextBlock Text="{Binding Sede, UpdateSourceTrigger=PropertyChanged}" Padding="10,0,0,0"></TextBlock>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.Effect>
<DropShadowEffect Color="#FF0A0A0A" Opacity="0.6"/>
</ComboBox.Effect>
</ComboBox>
现在,我该如何设置默认值? (像这样不起作用)
Now, how can I set the default values ? (like this doesn't work)
Sedi_Search.Sede = "ABC"
Sedi_Search.IdSede = 111
推荐答案
在视图模型中,您需要
new
您的Sedi_Search
使用您的默认值并将其添加到集合中。
In the view model, you need to
new
yourSedi_Search
with your default values and add it to the collection.
Sedi_Search= new Model_Sedi{Sede="ABC",IdSede=111};
Sedi.Add(Sedi_Search);
这篇关于如何在ComboBox多列中设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文