C#/WPF:依赖属性未更新绑定属性?
我正在尝试将依赖属性从我的 UserControl 绑定到我的 MainViewModel。
DependencyProperty 如下所示:
public static DependencyProperty ItemHasChangesProperty = DependencyProperty.Register("ItemHasChanges",
typeof(bool),
typeof(MyUserControl),
new PropertyMetadata(null));
public bool ItemHasChanges
{
get { return (bool)GetValue(ItemHasChangesProperty); }
set { SetValue(ItemHasChangesProperty, value); }
}
我的 XAML:
<local:MyUserControl ItemHasChanges="{Binding Path=Changes}" Grid.Row="4" />
现在,在调试和检查 bool Changes
的 Set-Accessor 时,我发现当我在 UserControl ItemHasChanges = true 中设置时,它永远不会被访问;
知道我在这里做错了什么吗?
谢谢!
干杯
I'm trying to bind a Dependency Property from my UserControl to my MainViewModel.
This is how the DependencyProperty looks like:
public static DependencyProperty ItemHasChangesProperty = DependencyProperty.Register("ItemHasChanges",
typeof(bool),
typeof(MyUserControl),
new PropertyMetadata(null));
public bool ItemHasChanges
{
get { return (bool)GetValue(ItemHasChangesProperty); }
set { SetValue(ItemHasChangesProperty, value); }
}
My XAML:
<local:MyUserControl ItemHasChanges="{Binding Path=Changes}" Grid.Row="4" />
Now when debugging and checking the Set-Accessor of bool Changes
, I see that it never gets accessed when I set in the UserControl ItemHasChanges = true;
Any idea what I'm doing wrong here?
Thanks!
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白了..我不得不改为
花
了我大约3小时才弄清楚..哈哈:-)
干杯
Got it.. I had to change
to
Took me about 3h to figure it out.. haha :-)
Cheers
您是否直接在控件上设置
ItemHasChanges
(如,而不是通过更新绑定源)?如果是这样,这将删除绑定。Are you setting
ItemHasChanges
on the control directly (as in, not by updating the binding source)? If so, that will remove the binding.