WPF下 ComboBox控件的SelectedValue属性双向绑定对象 的问题

shamohai5566 2012-09-26 12:28:47
我的ComboBox控件 在SeletedValue上双向绑定了一个属性MySelectedValue,现在的问题是我改变了ComboBox的选中项之后,MySelectedValue的值能随着改变,但是如果我再后台改变了MySelectedValue的值界面上ComboBox控件的选中项却没有任何修改,卡在这好几天了,高手请帮忙。
我的代码
[code=XAML]
<ComboBox x:Name="cmbGroupList" Style="{DynamicResource ComboBoxStyle1}" ItemsSource="{Binding OutputGroupList}" SelectedValue ="{Binding MySelectedGroup, Mode=TwoWay}"> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<ei:CallMethodAction MethodName="UpdateOutputListBox" TargetObject="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>

[/code]

private string m_selectedGroup;
public string SelectedGroup
{
get
{
return this.m_selectedGroup;
}
set
{
this.m_selectedGroup = value;
this.NotifyPropertyChanged("SelectedGroup");
}
}
...全文
1272 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shamohai5566 2012-10-24
  • 打赏
  • 举报
回复
问题解决了 谢谢大家
烟波钓 2012-09-28
  • 打赏
  • 举报
回复

private string m_selectedGroup;
public string MySelectedGroup
{
get
{
return this.m_selectedGroup;
}
set
{
this.m_selectedGroup = value;
this.NotifyPropertyChanged("MySelectedGroup");
}
}
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
我的ComboBox控件 在SeletedValue上双向绑定了一个属性MySelectedValue,现在的问题是我改变了ComboBox的选中项之后,MySelectedValue的值能随着改变,但是如果我再后台改变了MySelectedValue的值界面上ComboBox控件的选中项却没有任何修改,卡在这好几天了,高手请帮忙。
我的代码
XAML code

<ComboBox x:N……
[/Quote]

你绑定的属性名跟this.NotifyPropertyChanged所触发的属性名根本不同
sunny007sun 2012-09-27
  • 打赏
  • 举报
回复
你试试

<ComboBox x:Name="cmbGroupList" Style="{DynamicResource ComboBoxStyle1}" ItemsSource="{Binding OutputGroupList}"SelectedValuePath="{Binding SelectedGroup}" DisplayMemberPath="{Binding SelectedGroup}" SelectedValue ="{Binding MySelectedGroup, Mode=TwoWay}"> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<ei:CallMethodAction MethodName="UpdateOutputListBox" TargetObject="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>




8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧