In my following code
<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>
I am trying to use the style which is written in Generic.Xaml and it is as followes
<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>
But I am getting the following error -An object of the type "System.Windows.Controls.ControlTemplate" cannot be applied to a property that expects the type "System.Windows.Style"
I need help in this.regards
You need to use Template={StaticResource SearchUCHeaderButtonsStyle}instead of `Style="{StaticResource SearchUCHeaderButtonsStyle}" as you have edited Templet property of button not style. 
you are trying to set the style of ControlTemplate in a control which is button . So this error is coming. To avoid the above error you have to do
<Button Height="25" Width="50">
   <Button.Style>
     <Style TargetType="Button">
       <Setter Property="Template"
               Value="{StaticResource SearchUCHeaderButtonsStyle}"/>
     </Style>
   </Button.Style>
</Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With