效果如下:
分别有四种用法:
- 第一种 文字在右边
- 第二种 文字在中间
- 第三种 文字无
- 第四种 一组单选类型
- 实现思路看代码吧,还不够很完美...
一、引用方法:
<StackPanel
Grid.Row="2"
Margin="0,50,0,0"
Orientation="Horizontal">
<YOI:USwitchButton
Width="70"
Height="30"
Margin="10"
ActiveBackground="{DynamicResource PrimaryBlueColor}"
ActiveForeground="{DynamicResource TextSecundaryColor}"
ContentFalse="关闭"
ContentTrue="开启"
Cursor="Hand"
FontSize="14"
InactiveBackground="{DynamicResource TextWhiteColor}"
SwitchBorderRadius="15"
SwitchContentTemplate="Right" />
<YOI:USwitchButton
Width="80"
Height="30"
Margin="50,10,10,10"
ActiveBackground="{DynamicResource PrimaryBlueColor}"
ActiveForeground="{DynamicResource TextWhiteColor}"
ContentFalse="关闭"
ContentTrue="开启"
FontSize="14"
Foreground="{DynamicResource TextSecundaryColor}"
InactiveBackground="{DynamicResource TextWhiteColor}"
SwitchBorderRadius="15"
SwitchContentTemplate="Middle" />
<YOI:USwitchButton
Width="70"
Height="30"
Margin="10"
ActiveBackground="{DynamicResource PrimaryBlueColor}"
ActiveForeground="{DynamicResource PrimaryGreen}"
FontSize="14"
Foreground="{DynamicResource TextSecundaryColor}"
InactiveBackground="{DynamicResource TextWhiteColor}"
SwitchBorderRadius="15" />
<StackPanel
Grid.Row="2"
Margin="0,50,0,0"
Orientation="Vertical">
<YOI:USwitchButton
Width="70"
Height="30"
Margin="10"
ActiveBackground="{DynamicResource PrimaryBlueColor}"
ActiveForeground="{DynamicResource PrimaryGreen}"
FontSize="14"
Foreground="{DynamicResource TextSecundaryColor}"
InactiveBackground="{DynamicResource TextWhiteColor}"
SwitchBorderRadius="15"
SwitchType="1" />
<YOI:USwitchButton
Width="70"
Height="30"
Margin="10"
ActiveBackground="{DynamicResource PrimaryBlueColor}"
ActiveForeground="{DynamicResource PrimaryGreen}"
FontSize="14"
Foreground="{DynamicResource TextSecundaryColor}"
InactiveBackground="{DynamicResource TextWhiteColor}"
SwitchBorderRadius="15"
SwitchType="1" />
</StackPanel>
二、语雀笔记:
https://www.yuque.com/docs/share/a26bfbb5-5c40-4d4b-9daa-06b53da041b0?# 《WPF 自定义开关按钮实现》