WPF组合框选择项目绑定问题 [英] WPF Combobox Selected Item Binding Issue
本文介绍了WPF组合框选择项目绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我遇到了将选定项目与我的WPF组合绑定的问题。 Follwing是代码 -
XAML代码:
<
Hi All,
I am facing the issue with Binding the Slected Item with my WPF Combo. Follwing is the code -
XAML Code:
<
<ComboBox Grid.Row="3" Grid.Column="1" Margin="0,13,272,13" ItemsSource="{Binding Path=PersonTiers, Mode=TwoWay}" SelectedValue="{Binding Path=SelectedPersonTier, Mode=TwoWay}" SelectedValuePath="Content"/>
查看型号代码
View Model Code
public List<string> PersonTiers
{
get
{
List<string> lstPersonTiers = new List<string>();
string[] TierArray = Globalization.TierString.Split(',');
foreach (var item in TierArray)
{
lstPersonTiers.Add(item);
}
return lstPersonTiers;
}
}
private string _selectedPersonTier;
public string SelectedPersonTier
{
get { return //What should I write here ?.ToString(); }
set
{
if (_selectedPersonTier != value)
{
_selectedPersonTier = value;
this.OnPropertyChanged("SelectedPersonTier");
}
}
}
我能够获得组合列表,但不是选定项目。请帮忙。
I am able to get the Combo List , but not the Selected Item . Please help .
推荐答案
_selectedPersonTier应该在你的get属性SelectedPersonTier中返回。所以get应该如下所示:
_selectedPersonTier should be returned in your get for the property SelectedPersonTier. So the get should appear as follows:
get { return _selectedPersonTier; }
这也应该解决所选项目问题。
此致,
SeniorCrispy。
That should fix the selected item issue as well.
Regards,
SeniorCrispy.
这篇关于WPF组合框选择项目绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文