4

MahApp.Metro を使用して wpf アプリケーションをテストしています。どういうわけか、ToggleSwitch のスタイルを変更できません。スイッチの前景や背景などの単純なプロパティを変更したいだけです。私は何を間違っていますか?

メインウィンドウ.xaml

<Style  x:Key="flyoutToggleSwitchStyle" TargetType="{x:Type Controls:ToggleSwitch}" BasedOn="{StaticResource {x:Type Controls:ToggleSwitch}}">
        <Setter Property="BorderBrush" Value="WhiteSmoke"/>
        <Setter Property="Background" Value="White"/>    
        <Setter Property="Foreground" Value="Yellow"/>
        <Setter Property="OnLabel" Value="Yes"/>  <!--<<<---THIS WORKS!!-->
        <Setter Property="OffLabel" Value="No"/>
    </Style>

<Controls:ToggleSwitch Style="{StaticResource flyoutToggleSwitchStyle}">
    <Controls:ToggleSwitch.Header>
           <TextBlock>
                    Test                            
           </TextBlock>
     </Controls:ToggleSwitch.Header>
 </Controls:ToggleSwitch>
4

2 に答える 2

2

位置の色を変更できる新しいToggleSwitchプロパティが追加されました (v0.14 でテスト済み)。例:SwitchForegroundON

<controls:ToggleSwitch SwitchForeground="{StaticResource MyGreen}" />
于 2014-12-01T23:21:22.767 に答える
1

問題は、Mahapps.Metro ToggleSwitch では、元のテンプレート定義に TemplateBinding または Key が定義されていないため、ほとんどのプロパティをスタイル内で変更できないことです。
そのため、新しいテンプレートを作成することによってのみスタイルを変更できます。このために、ToggleSwitch および ToggleSwitchButton テンプレートを変更する必要があります。

テンプレートのGitHub ソースに関する問題

于 2013-10-21T08:38:37.427 に答える