-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSwitch.xaml
29 lines (26 loc) · 1.48 KB
/
Switch.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bc="clr-namespace:BmLib.Controls"
xmlns:conv="clr-namespace:BmLib.Converters"
>
<ControlTemplate x:Key="SwitchTemplateKey" TargetType="{x:Type bc:Switch}">
<ControlTemplate.Resources>
<conv:BoolToVisibilityPropConverter TrueValue="Visible" FalseValue="Hidden" x:Key="BoolToVisibilityConverter" />
<conv:BoolToVisibilityPropConverter TrueValue="Hidden" FalseValue="Visible" x:Key="InvertedBoolToVisibilityConverter" />
</ControlTemplate.Resources>
<Grid>
<ContentPresenter
Content="{TemplateBinding ContentOn}"
Visibility="{Binding IsSwitchOn,
RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}" />
<ContentPresenter
Content="{TemplateBinding ContentOff}"
Visibility="{Binding IsSwitchOn,
RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource InvertedBoolToVisibilityConverter}}" />
</Grid>
</ControlTemplate>
<Style TargetType="{x:Type bc:Switch}" x:Key="{x:Type bc:Switch}">
<Setter Property="Template" Value="{StaticResource SwitchTemplateKey}" />
<Setter Property="Focusable" Value="True" />
</Style>
</ResourceDictionary>