简体   繁体   English

使用 XAML 设置器设置自定义附加属性

[英]Set a custom Attached Property with a XAML Setter

I wanted to set a custom Attached Property that I attached to my Textboxes.我想设置一个附加到我的文本框的自定义附加属性

My name space is correctly imported, and used for other things in my UserControl so it works fine.我的名称空间已正确导入,并用于我的 UserControl 中的其他内容,因此它工作正常。

I can't seem to find the correct syntax for this.我似乎找不到正确的语法。

Here is what I currently have (I tried to add brackets at different places, but it doesn't work):这是我目前拥有的(我试图在不同的地方添加括号,但它不起作用):

... 
  <DataTrigger ...>
    <Setter ... />
    <Setter Property="(MyCustomXMLNS:TextBoxExtend).MyProperty" Value="..." />
  </DataTrigger>
</Style.Triggers>

This is only a syntax problem here, do you guys know how to achieve this?这只是一个语法问题,你们知道如何实现吗?

You do not use parentheses in a Setter for an attached property, so the correct syntax is您不在 Setter 中为附加属性使用括号,因此正确的语法是

<Setter Property="MyCustomXMLNS:TextBoxExtend.MyProperty" Value="..."/>

You would use parentheses when the property is the source of a Binding, like当属性是绑定的源时,你会使用括号,比如

<DataTrigger Binding="{Binding Path=(MyCustomXMLNS:TextBoxExtend.MyProperty)}"
             Value="...">

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

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