2015-07-06 63 views
0

我有我的ViewModel属性,我需要绑定到我的行为BindableProperty,但我似乎无法让它绑定。从ViewModel绑定到行为

private int _test; 
    public int Test { 
     get { 
      return _test; 
     } 
     set { 
      if (SetProperty (ref _test, value)) { 
       _profileIsDirty = true; 
       NotifyPropertyChanged ("AllowUpdate"); 

      } 

     } 
    } 

这里是行为的性质

 public static readonly BindableProperty MinLengthProperty = BindableProperty.Create("MinLength", typeof(int), typeof(MinLengthValidator), 0); 

    public int MinLength 
    { 
     get { return (int)GetValue(MinLengthProperty); } 
     set { SetValue(MinLengthProperty, value); } 
    } 

这是在视图模型的财产,这是我正在试图绑定到它在XAML

<behave:TelephoneNumberValidatorBehaviour x:Name="phoneValidator" MinLength="{Binding Test, Mode=OneWay}"/> 

但永不结合。我在这里做错了什么?

回答

0

您是否尝试将NotifyPropertyChanged的值更改为“Test”而不是“AllowUpdate”?否则UI永远不会被通知该值已经改变了Test。相反,它会引发AllowUpdate属性发生更改的值,这在ViewModel中不存在。

+0

是的,我有,在SetProperty方法中有一个内置的通知,所以它不是不幸的。 –

0

BindableProperty.Create的第三个参数应该是BindableProperty定义的类的类型。根据你的样本,我猜它应该是typeof(TelephoneNumberValidatorBehaviour)而不是 typeof(MinLengthValidator)