問題描述
如何解決“在類型'ControlTemplate'中找不到可附加屬性'觸發器'”? (How to resolve "The attachable property 'Triggers' was not found in type 'ControlTemplate'"?)
我已經向 UpdateBtn 添加了一個控件模板,遵循此 snippet 但我收到一條錯誤消息,指出在 ControlTemplate 上找不到 Triggers
屬性。這個想法是將故事板綁定到按鈕的 IsEnabled
屬性。
Error 5 The attachable property 'Triggers' was not found in type 'ControlTemplate'.
我研究了錯誤,似乎該屬性是 ControlTemplate,這是一個 WPF應用程序不是 Windows。所以不確定為什麼 xaml 設計器中會顯示錯誤。
參考解法
方法 1:
Your XAML structure is
<Button.Template>
<ControlTemplate.Triggers>
...
</ControlTemplate.Triggers>
</Button.Template>
but you need something like
<Button.Template>
<ControlTemplate TargetType="Button">
<ControlTemplate.Triggers>
...
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>