0
主窗口有組合框下面的XAML將圖片添加到組合框的值
MainWindowViewModel.xaml
<ComboBox Name="CountryComboBox" HorizontalAlignment="Left" Margin="40,170,0,0" VerticalAlignment="Top" Width="220"
ItemsSource="{Binding Countries, Mode=OneWay}"
SelectedValue="{Binding SelectedCountry, Mode=TwoWay}">
</ComboBox>
MainWindowViewModel.cs
private string _SelectedCountry;
public string SelectedCountry
{
get
{
return _SelectedCountry;
}
set
{
_SelectedCountry = value;
OnPropertyChanged("SelectedCountry");
}
}
public List<string> Countries {get; set;}
public MainViewModel()
{
Countries = new List<string>();
var a = "Avganistan";
var b = "Azerbeijan";
Countries.Add(a);
Countries.Add(b);
}
我如何添加圖像這個國家的combobox值?
這是沒有必要更換'List'用'ObservableCollection'導致它在ViewModel' – monstr 2014-08-28 09:43:40
的'構造函數初始化,這是沒有必要要麼執行'INotifyPropertyChanged'接口,但它是很好的做法。 – Sheridan 2014-08-28 09:52:23