如何解決“在類型'ControlTemplate'中找不到可附加屬性'觸發器'”? (How to resolve "The attachable property 'Triggers' was not found in type 'ControlTemplate'"?)


問題描述

如何解決“在類型'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>

(by Brian VarFratyx)

參考文件

  1. How to resolve "The attachable property 'Triggers' was not found in type 'ControlTemplate'"? (CC BY‑SA 2.5/3.0/4.0)

#wpf #storyboard #Triggers #controltemplate #xaml






相關問題

usercontrol wpf 靜態內存 (usercontrol wpf static memory)

將圖像加載到面板 (Load image to panel)

我的 WPF 自定義控件的數據上下文正在取代父級的 (My WPF custom control's Data Context is superseding parent's)

是否可以更改 WPF 控件的父級 (Is it possible to change parent of WPF control)

WPF MVVM 鏈接視圖 (WPF MVVM Linked Views)

wpf 樹視圖 mvvm (wpf treeview mvvm)

應用啟動後更改應用圖標 (Change application icon after app launched)

在VB中過濾一個wpf collectionviewsource? (Filter a wpf collectionviewsource in VB?)

如何使 DockPanel 中的項目擴展以適應 WPF 中的所有可用空間? (How to make items in a DockPanel expand to fit all available space in WPF?)

使用 IsCheckable="True" 綁定 MenuItem 中的鍵時出現問題,為什麼? (Problems binding keys in MenuItem's with IsCheckable="True", why?)

如何將文本框的borderBrush屬性綁定到viewmodel中的屬性,類型轉換錯誤 (How to bind the borderBrush property of a textbox to a property in viewmodel, type conversion error)

Painter 應用程序的自定義控件以顯示不同的橡皮擦 (Custom Control for Painter application to show different erasers)







留言討論