如何解决"The attachable property 'Triggers' was not found in type '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 设计器中会显示错误。

任何人都可以告诉我我在实施中哪里出了问题吗?

按钮和关联 ns 的 XAML 如下:

<Window x:Class="MongoDBApp.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:email_validator="clr-namespace:MongoDBApp.Validator"
        Title="Orders Dashbord"
        Width="800"
        Height="500">

    <Grid>
        <TabControl>
            <TabItem Header="Customer">
                <Grid>

                    <Button x:Name="updateBtn"
                            Width="75"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Top"
                            Command="{Binding Path=UpdateCommand}"
                            Content="Update">
                        <Button.ToolTip>
                            <ToolTip>
                                <StackPanel>
                                    <TextBlock>Updates customer record</TextBlock>
                                </StackPanel>
                            </ToolTip>
                        </Button.ToolTip>
                        <Button.Template>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Content" Duration="00:00:00.8" RepeatBehavior="Forever">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00.0" Value="Loading"/>
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="Loading."/>
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00.4" Value="Loading.."/>
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00.6" Value="Loading..."/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </Trigger.EnterActions>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </Button.Template>
                    </Button>


                </Grid>
            </TabItem>           
        </TabControl>
    </Grid>

</Window>

你的XAML结构是

<Button.Template>
    <ControlTemplate.Triggers>
         ...
    </ControlTemplate.Triggers>
</Button.Template>

但你需要像

这样的东西
<Button.Template>
    <ControlTemplate TargetType="Button">
        <ControlTemplate.Triggers>
          ...
        </ControlTemplate.Triggers>
    </ControlTemplate>
</Button.Template>