Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
this is my button control

XML
<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 3: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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900