绑定在Windows应用商店应用中不起作用

时间:2014-10-12 19:12:42

标签: c# wpf xaml windows-store-apps winrt-xaml

以下是继承自ParamModel

DependencyObject课程
public class ParamsModel : DependencyObject
{
    public object MyProperty
    {
        get { return (object)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }

    public static readonly DependencyProperty MyPropertyProperty =
        DependencyProperty.Register("MyProperty", typeof(object), typeof(ParamsModel), new PropertyMetadata(null));

    public ParamsModel()
    {

    }

}

我已在XAML中提及此课程,如下所示

<TextBox Text="{Binding DataContext.MyName,ElementName=pageRoot}" />
<ListBox ItemsSource="{Binding MyItems}"
         Width="500"
         Height="500">
    <local:ParamsModel MyProperty="{Binding DataContext.MyName,ElementName=pageRoot}" />
</ListBox>

我已将断点设置在MyProperty setter上,该断点未在运行时命中,但同一个类Constructor正在命中。有人可以帮我这个

2 个答案:

答案 0 :(得分:1)

这是因为绑定机制不会调用依赖属性的CLR属性。它直接调用GetValue/SetValue

答案 1 :(得分:0)

我一直在尝试绑定到Store App中的DependencyObject视图模型,除非我将PropertyMetaData参数设置为null而不是新的PropertyMetadata(null),否则它将无法工作。

相关问题