XamlParseException Failed to assign to property. Binding not working with attached property

前端 未结 2 1390
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 17:40

I want to create custom text box with attached property for Windows Store app. I am following this solution. Now it uses hard coded value as property value but I want to set

相关标签:
2条回答
  • 2021-01-12 17:57

    Incorrect

    public static readonly DependencyProperty TypeProperty =
        DependencyProperty.RegisterAttached("Type", typeof(InputType), typeof(TextBox), new PropertyMetadata(default(InputType), OnTypeChanged));
    

    Correct

    public static readonly DependencyProperty TypeProperty =
                DependencyProperty.RegisterAttached("Type", typeof(InputType), typeof(Input), new PropertyMetadata(default(InputType), OnTypeChanged));
    
    0 讨论(0)
  • 2021-01-12 18:13

    This is a pretty common mistake. The problem is, binding targets cannot be CLR properties in XAML. It's just the rules. A binding source can be a CLR property, just fine. The targets simply must be dependency properties.

    We all get the error! :)

    enter image description here

    I describe the whole thing here: http://blogs.msdn.com/b/jerrynixon/archive/2013/07/02/walkthrough-two-way-binding-inside-a-xaml-user-control.aspx

    Best of luck.

    0 讨论(0)
提交回复
热议问题