大家好, 我有一个问题,我想将我的WPF组合框与我使用正则表达式提取的值绑定。这是我的代码:
string pattern = "/^dhcp pool.*/g";
Console.WriteLine(pattern);
MatchCollection matches = Regex.Matches(_str, pattern);
foreach(Match match in matches)
{
Console.WriteLine("+++++++++++++dhcp pool is ++++++++++++++" + match.Groups[1].Value);
DHCPoolName = match.Groups[1].Value;
}
DHCPPoolName是我绑定为我的组合框的ItemSorurce的属性的名称。
XAML代码:
<ComboBox
Grid.Column="1"
Grid.Row="1"
Margin="0,4"
ItemsSource="{Binding DHCPoolName}">
</ComboBox>
DHCPPoolName属性:
public string DHCPoolName
{
// Retreive value from Configuration Library
get
{
//Console.WriteLine("get WpaWpa2RadiusKey");
return this.ConfigurationLibrary.ConfigLibraryDhcpPoolName;
}
// Set value in Configuration Library
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryDhcpPoolName, value))
{
//Console.WriteLine("set WpaWpa2RadiusKey");
this.ConfigurationLibrary.ConfigLibraryDhcpPoolName = value;
// ValidateWLAN1RadiusKey(value);
this.OnPropertyChanged("DHCPoolName");
}
}
}
我没有成功地将我的组合框与我提取的值绑定,任何人都可以告诉我我在哪里做错了吗?
答案 0 :(得分:0)
您可以定义字符串Collection
private ObservableCollection<string> dhcppoolname;
public ObservableCollection<string> DHCPoolName
{
get
{
if(dhcppoolname == null)
{
dhcppoolname = new ObservableCollection<string>();
}
return dhcppoolname;
}
set
{
dhcppoolname = value;
OnPropertyChanged("DHCPoolName");
}
}
在foreach循环中
foreach(Match match in matches)
{
Console.WriteLine("+++++++++++++dhcp pool is ++++++++++++++" + match.Groups[1].Value);
DHCPoolName.Add(match.Groups[1].Value);
}