无法在WPF中使用样式在按钮上设置文本

问题描述:

这是我的按钮控件



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无法在按钮上设置文字



我的尝试:



我的风格





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 ?

添加以下xaml解决问题

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