我想把我的UserControl中的一个依赖属性绑定到我的MainViewModel中。
这是依赖属性的代码:
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;
时,它从未被访问。你有什么想法吗?感谢!祝好!
OneWayToSource
模式。 我们可以使用OneWay
代替。 - Justin SkilesTwoWay
也可以使用。这也浪费了我大约一个小时的时间,认为我的属性没有设置其值。 - Dan