Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型为“的对象”;System.Windows.Controls.ControlTemplate“;无法应用于预期类型为“的属性”;System.Windows.Style“;_C#_Wpf_Silverlight_Xaml_Prism - Fatal编程技术网

C# 类型为“的对象”;System.Windows.Controls.ControlTemplate“;无法应用于预期类型为“的属性”;System.Windows.Style“;

C# 类型为“的对象”;System.Windows.Controls.ControlTemplate“;无法应用于预期类型为“的属性”;System.Windows.Style“;,c#,wpf,silverlight,xaml,prism,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 SearchUCH

在我下面的代码中

<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”的属性


我需要这方面的帮助。

您需要使用
模板={StaticResource SearchUCHeaderButtonsStyle}
而不是`Style=“{StaticResource SearchUCHeaderButtonsStyle}”,因为您已经编辑了按钮而不是样式的模板属性

您正试图在一个控件中设置ControlTemplate的样式,该控件是button。所以这个错误就来了。要避免上述错误,您必须执行以下操作

<Button Height="25" Width="50">
   <Button.Style>
     <Style TargetType="Button">
       <Setter Property="Template"
               Value="{StaticResource SearchUCHeaderButtonsStyle}"/>
     </Style>
   </Button.Style>
</Button>