<!-- 兩個按鈕來回切換樣式 --> <Style x:Key="SwicthFunctionMetroToggleButton" TargetType="{x:Type ToggleButton}"> <Setter Property="Background" Value="White" /> <Setter Property="BorderBrush" Value="Black" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="MetroControls:ControlsHelper.CornerRadius" Value="0" /> <Setter Property="FontFamily" Value="Meiryo" /> <Setter Property="FontSize" Value="15" /> <Setter Property="FontWeight" Value="Bold" /> <Setter Property="Foreground" Value="Black" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToggleButton"> <Grid> <Border x:Name="_Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.CornerRadius), Mode=OneWay}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <Border x:Name="DisabledVisualElement" Background="{DynamicResource ControlsDisabledBrush}" CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.CornerRadius), Mode=OneWay}" IsHitTestVisible="False" Opacity="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <MetroControls:ContentControlEx x:Name="PART_ContentPresenter" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(MetroControls:ControlsHelper.ContentCharacterCasing)}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="_Border" Property="Background" Value="#4e81bd" /> <Setter Property="Foreground" Value="White" /> </Trigger> <Trigger Property="IsChecked" Value="False"> <Setter TargetName="_Border" Property="Background" Value="White" /> <Setter Property="Foreground" Value="Black" /> </Trigger> <!--<Trigger Property="IsKeyboardFocusWithin" Value="True"> <Setter TargetName="_Border" Property="Background" Value="#4e81bd" /> <Setter Property="Foreground" Value="White" /> </Trigger>--> <!--<Trigger Property="IsEnabled" Value="False"> <Setter TargetName="DisabledVisualElement" Property="Opacity" Value="0.7" /> <Setter TargetName="PART_ContentPresenter" Property="Opacity" Value="0.3" /> </Trigger>--> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="_Border" Property="Background" Value="#e6e6e6"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <!--<Style.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="Background" Value="{DynamicResource GrayBrush2}" /> <Setter Property="BorderBrush" Value="{DynamicResource GrayBrush5}" /> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="IsChecked" Value="False" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="{DynamicResource GrayBrush8}" /> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="IsChecked" Value="True" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="{DynamicResource GrayBrush3}" /> </MultiTrigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="{DynamicResource GrayBrush7}" /> </Trigger> <Trigger Property="IsKeyboardFocusWithin" Value="True"> <Setter Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorderBrush}" /> </Trigger> </Style.Triggers>--> </Style>
使用以下ide
<ToggleButton x:Name="uiuserdataImpTbtnContent" Style="{StaticResource SwicthFunctionMetroToggleButton}" Width="80" Height="25" Content="{x:Static const:Resources.TextImportResultLabContent}" Margin="0,1,1,0" FontSize="11" IsChecked="{Binding TBContentIsChecked}" IsEnabled="{Binding TBTagIsChecked}" Visibility="{Binding IsContentVisibility}" /> <ToggleButton x:Name="uiuserdataImpTbtnTag" Style="{StaticResource SwicthFunctionMetroToggleButton}" Width="80" Height="25" Content="{x:Static const:Resources.TextImportResultLabTag}" Margin="-2,1,1,0" FontSize="11" IsChecked="{Binding TBTagIsChecked}" IsEnabled="{Binding TBContentIsChecked}" VerticalAlignment="Top" Visibility="{Binding IsTagVisibility}" />