使用MaterialDesignInXaml更改默认的ToggleButton

时间:2018-09-10 21:32:02

标签: xaml material-design-in-xaml

我的WPF应用程序中有一些醒目的彩色编码ToggleButtons。我正在尝试MaterialDesignInXAML,但是切换按钮默认为很小的开关。如何使用较大的切换按钮?

您可以在此处查看默认设置:

Very small switch

我使用TextBlocks作为按钮标签以适应自动换行。

每个ToggleButton都是这样的:

<ToggleButton Width="200" Height="200" Grid.Row="0" Grid.Column="0" Margin="10" Name="Game0" Foreground="{Binding Game0TextColor}" Background="{Binding Game0Color}"> <!--Use TextBlock for word wrapping button text--> <TextBlock TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Center" FontSize="22" Foreground="{Binding Game0TextColor}" Text="{Binding Game0Title}" /> </ToggleButton>

1 个答案:

答案 0 :(得分:0)

假设您已拉入指定的样板,则可以在特定视图中覆盖默认样式,如下所示:

<Window.Resources>
    <ResourceDictionary>
        <!-- 
        Override style for ToggleButton to use because default is a small switch 
        Try also MaterialDesignFlatPrimaryToggleButton
        -->
        <Style TargetType="ToggleButton" 
               BasedOn="{StaticResource MaterialDesignActionToggleButton}" />
    </ResourceDictionary>
</Window.Resources>

enter image description here

请参见Toggle Button examples on the wiki page并在演示应用程序中。

如果您想在整个应用范围内更改样式或将其排除在外,还可以查看Overriding-Default-Styles的指南。