- <Window x:Class="WPF练习.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:WPF练习"
- mc:Ignorable="d"
- Title="MainWindow"
- Height="450"
- Width="800">
- <Window.Resources>
- <ControlTemplate TargetType="CheckBox"
- x:Key="SwitchButtonTemp">
- <Border CornerRadius="5"
- BorderBrush="Gray"
- BorderThickness="1">
- <Grid>
- <TextBlock Text="开启"
- VerticalAlignment="Center" Margin="10,0,0,0"/>
- <TextBlock Text="关闭"
- VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0"/>
- <Border Width="40"
- Height="26"
- Background="Orange"
- CornerRadius="5"
- HorizontalAlignment="Left"
- Margin="1,0,0,0"
- Name="border" />
- </Grid>
-
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsChecked"
- Value="True">
- <Setter Property="Margin"
- Value="47,0,0,0"
- TargetName="border">
-
- </Setter>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- <Style x:Key="FocusVisual">
- <Setter Property="Control.Template">
- <Setter.Value>
- <ControlTemplate>
- <Rectangle Margin="2" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
- </Window.Resources>
- <Grid>
- <StackPanel>
- <CheckBox Template="{StaticResource SwitchButtonTemp}"
- Height="30"
- Width="90"
- IsChecked="True" />
- </StackPanel>
- </Grid>
- </Window>
复制代码 效果:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |