2

とを変更するスタイルを作成Stylesするための最良の方法がわかりません。背景と境界線のプロパティがあるため、テンプレートに を使用しました。しかし、プロパティを持っていません。デフォルトの外観が上書きされていないため、テンプレートとして使用してもうまくいきません。ButtonForegroundIsMouseOverIsPressedBorderCornerRadiusBorderForegroundButton

ButtonテンプレートをForeground動作でスタイルするより良い方法は何ですか? たぶん、境界線の内側にラベルを使用していますか?

App.xaml は次のとおりです。

<Application.Resources>
    <Style TargetType="Button" x:Key="MyButton">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="MinHeight" Value="34"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="shortcutbutton"  
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="Gray">
                        <ContentPresenter Margin="2" 
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center" 
                                  RecognizesAccessKey="True"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="shortcutbutton" Property="Background" Value="#FFDADADA" />
                            <Setter TargetName="shortcutbutton" Property="BorderBrush" Value="#EEEEEE" />
                            <!--<Setter TargetName="Border" Property="Foreground" Value="Black" />-->
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="shortcutbutton" Property="Background" Value="DarkGray" />
                            <Setter TargetName="shortcutbutton" Property="BorderBrush" Value="Black" />
                            <!--<Setter TargetName="Border" Property="Foreground" Value="Red" />-->
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

そしてxaml:

    <StackPanel HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100">
        <Button Content="Button" Height="41" Style="{DynamicResource MyButton}"/>
    </StackPanel>
4

2 に答える 2

2

あなたができることは、あなたの中のすべてのテキスト要素がその色になるようTextElementに、の添付プロパティを設定することです:BorderBorder

<ControlTemplate.Triggers>
   <Trigger Property="IsMouseOver" Value="true">
       <Setter TargetName="shortcutbutton" Property="Background" Value="#FFDADADA" />
       <Setter TargetName="shortcutbutton" Property="BorderBrush" Value="#EEEEEE" />
       <Setter TargetName="shortcutbutton" Property="TextElement.Foreground" Value="White"/>
   </Trigger>
   ...
</ControlTemplate.Triggers>
于 2013-06-13T15:06:23.433 に答える