c# - 类型为 "System.Windows.Controls.ControlTemplate"的对象不能应用于需要类型为 "System.Windows.Style"的属性

标签 c# wpf silverlight xaml prism

在我下面的代码中

<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
            <TextBlock Text="Opportunity" Height="25" Width="50"></TextBlock>
            <Button Height="25" Width="50" Style="{StaticResource SearchUCHeaderButtonsStyle}">

            </Button>
            <Button Height="25" Width="50"></Button>
        </StackPanel>

我正在尝试使用用 Generic.Xaml 编写的样式,如下所示

<ControlTemplate x:Key="SearchUCHeaderButtonsStyle" TargetType="Button">
        <Border Name="Border" CornerRadius="2" BorderThickness="1" Background="#C0C0C0" BorderBrush="#404040">
            <ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter TargetName="Border" 
                          Property="BorderBrush" Value="#202020" />
            </Trigger>
            <Trigger Property="IsDefaulted" Value="true">
                <Setter TargetName="Border" 
                          Property="BorderBrush" Value="#202020" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="Border" 
                          Property="Background" Value="#808080" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="Border" 
                          Property="Background" Value="#E0E0E0" />
                <Setter TargetName="Border" 
                          Property="BorderBrush" Value="#606060" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter TargetName="Border" 
                          Property="Background" Value="#EEEEEE" />
                <Setter TargetName="Border" 
                          Property="BorderBrush" Value="#AAAAAA" />
                <Setter Property="Foreground" Value="#888888"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

但我收到以下错误 - “System.Windows.Controls.ControlTemplate”类型的对象不能应用于需要“System.Windows.Style”类型的属性

我需要帮助。问候

最佳答案

您需要使用 Template={StaticResource SearchUCHeaderButtonsStyle} 而不是 `Style="{StaticResource SearchUCHeaderButtonsStyle}"因为您编辑的是按钮的 Templet 属性而不是样式。

关于c# - 类型为 "System.Windows.Controls.ControlTemplate"的对象不能应用于需要类型为 "System.Windows.Style"的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23064447/

相关文章:

c# - 如何测试 IActionResult 及其内容

c# - 在 using 语句内部还是外部返回?

wpf - 如何禁用取消选择 ListView 中的项目?

c# - WPF 2 ListView 简单的选定项数据绑定(bind)

silverlight 和 DataContractSurrogates 中都存在类型

c# - 如何获取条件为字符串数组的记录

c# - 更新用户的成员角色

c# - ContentControl 中的 GroupBox - 支持由绑定(bind)到 ContentControl 的内容实现的 IDataErrorInfo

c# - Silverlight 5 VS 2012 单元测试

c# - Farseer 物理教程,帮助文件