Click here to Skip to main content
14,447,320 members
Rate this:
Please Sign up or sign in to vote.
See more:
this is my button control

<Button Grid.Row="1"  Height="49" Width="249" Style="{StaticResource TriggerStyleBlue}" Name="btnStart" Click="btnStart_Click" Cursor="Hand" VerticalContentAlignment="Top" Content="Start Now" Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Left" />


i can not set text on the button

What I have tried:

my style

<Style x:Key="TriggerStyleBlue" TargetType="{x:Type Button}">
            <Setter Property="Foreground">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#9B000000" Offset="0"/>
                        <GradientStop Color="White" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border TextBlock.Foreground="{TemplateBinding Foreground}"
                                  x:Name="Border"
                                  CornerRadius="1"
                                  BorderThickness="1">
                            <Border.Background>
                                <ImageBrush ImageSource= "..\Resources\BTN_REGistryscan_Normal.jpg"  />
                            </Border.Background>
                            <!--<Border.Effect>
                                <DropShadowEffect/>
                            </Border.Effect>-->
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">
                                <!--<Setter TargetName="Border" Property="Border.Effect" Value="{x:Null}"/>-->
                                <Setter  Property="Background" TargetName="Border">
                                    <Setter.Value>
                                        <ImageBrush ImageSource="..\Resources\BTN_REGistryscan_Down.jpg"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" TargetName="Border">
                                    <Setter.Value>
                                        <ImageBrush ImageSource="..\Resources\BTN_REGistryscan_Hover.jpg"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


What iam doing wrong ?
Posted
Updated 27-Sep-18 4:30am
Comments
srilekhamenon 27-Sep-18 9:32am
   
https://stackoverflow.com/questions/9913422/change-button-background-image-on-hover-click-using-a-template

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Add following xaml solve problem
</Border.Background>
                            <ContentPresenter x:Name="cp" 
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Margin="{TemplateBinding Padding}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        RecognizesAccessKey="True"  />
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100