我有這個類如何通過自定義類後面的代碼填充WPF Combobox?
public class UILanguagesModel : INotifyPropertyChanged
{
public UILanguagesModel()
{
IList<UILanguage> list = new List<UILanguage>();
UILanguage english = new UILanguage();
english.Culture = "en";
english.SpecCulture = "en-US";
english.EnglishName = "English";
UILanguage spanish = new UILanguage();
spanish.Culture = "es";
spanish.SpecCulture = "es-ES";
spanish.EnglishName = "Spanish";
list.Add(english);
list.Add(spanish);
_languages = new CollectionView(list);
}
private readonly CollectionView _languages;
private UILanguage _language;
public CollectionView Languages
{
get { return _languages; }
}
public UILanguage Language
{
get { return _language; }
set
{
if (_language == value) return;
_language = value;
OnPropertyChanged("Language");
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public sealed class UILanguage
{
public string EnglishName { set; get; }
public string Culture { set; get; }
public string SpecCulture { set; get; }
}
我需要用 「EnglisgName」 WPF組合框來填充。
怎麼辦?
謝謝!
標記XAML
<ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="0,1,0,0"
Name="cmbLanguages" VerticalAlignment="Top" Width="207" />
你能顯示標記嗎? –
@ShoaibShaikh是這裏。 –
你爲什麼要以這種方式爲你的UI做多種語言支持?它有可能檢測出當前的系統文化。我討厭讓我選擇一種我甚至無法閱讀的語言的程序。 –