简体   繁体   English

MVVM Light中具有DependencyProperty的UserControl

[英]UserControl with DependencyProperty in MVVM Light

I have a UserControl that add a DependencyProperty for it . 我有一个为它添加DependencyProperty的UserControl。

    public const string TextValuePropertyName = "TextValue";
      public string TextValue
    {
        get
        {
            return (string)GetValue(TextValueProperty);
        }
        set
        {
            SetValue(TextValueProperty, value);
        }
    }
     public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register(
        TextValuePropertyName,
        typeof(string),
        typeof(FormatUserControl),
        new UIPropertyMetadata());

and use it in another Usercontrol 并在另一个Usercontrol中使用它

       <local:FormatUserControl   TextValue="{Binding Subject,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  />

When i use this don't set value for this property when i change Subject value? 当我使用此属性时,更改Subject值时是否不为此属性设置值?

Your FormatUserControl is the class and you should register the property for it not for the NumberFormatUserControl like this (I am not aware what is the relationship between the two user controls): 您的FormatUserControl是类,您应该为它注册属性,而不是像这样为NumberFormatUserControl注册属性(我不知道两个用户控件之间的关系是什么):

public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register(
    TextValuePropertyName,
    typeof(string),
    typeof(FormatUserControl),
    new UIPropertyMetadata());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM