[英]How to display values in WPF combobox already displaying in textbox above?
我正在基於WPF
, C#
和MVVM
的項目中工作。 它基本上是可通過telnet配置的聯網設備。 問題是我有一個文本框,其中顯示了一些值。 我想從文本框中獲取這些值並將其顯示在組合框中。 請參閱隨附的屏幕截圖,該屏幕截圖對所有人都更加清晰。
<ComboBox
Grid.Column="1"
Grid.Row="0"
Margin="0,4"
Text="{Binding ApGroupsManagementApMac}">
</ComboBox>
public string ApGroupsManagementApMac
{
// Retreive value from Configuration Library
get
{
//Console.WriteLine("get WpaWpa2RadiusKey");
return this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac;
}
// Set value in Configuration Library
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac, value))
{
//Console.WriteLine("set WpaWpa2RadiusKey");
this.ConfigurationLibrary.ConfigLibraryApGroupsManagementApMac = value;
// ValidateWLAN1RadiusKey(value);
this.OnPropertyChanged("ApGroupsManagementApMac");
}
}
}
string _apGroupsManagementApMac;
public string ConfigLibraryApGroupsManagementApMac
{
get
{
return _apGroupsManagementApMac;
}
set
{
if (String.Equals(_apGroupsManagementApMac, value))
{
return;
}
_apGroupsManagementApMac = value;
OnPropertyChanged("ConfigLibraryApGroupsManagementApMac");
}
}
還有一件事是,我只希望組合框中的這些值從f8
開始,以0
結尾。 任何幫助將是非常可觀的。
您應該使用來自配置庫的值創建一個集合,然后將此集合綁定到組合框的ItemsSource。
編輯
您應該創建一個屬性來存儲配置庫中的選項(為簡單起見,在此示例中,它只是一個字符串ObservableCollection):
public ObservableCollection<string> Collection
{
get;
set;
}
然后使用選項填充集合。 只需為此創建一個方法(我不知道您的配置庫的外觀)。 最后,您必須將集合綁定到ComboBox的ItemsSource:
<ComboBox
Grid.Column="1"
Grid.Row="0"
Margin="0,4"
ItemsSource="{Binding Collection}">
</ComboBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.