我正在尝试将来自UserControl的Dependency属性绑定到我的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;
知道我在这里做错了吗?
谢谢!
干杯
答案 0 :(得分:9)
知道了......我不得不改变
<local:MyUserControl ItemHasChanges="{Binding Path=Changes}" Grid.Row="4" />
到
<local:MyUserControl ItemHasChanges="{Binding Path=Changes, Mode=OneWayToSource}" Grid.Row="4" />
花了我3个小时来搞清楚..哈哈: - )
干杯
答案 1 :(得分:0)
您是否直接在控件上设置ItemHasChanges
(例如,不是通过更新绑定源)?如果是这样,那将删除绑定。