我发现这种风格here并将其添加到我的Window.Resources
:
<Style x:Key="Custom.ToggleSwitch.Win10"
BasedOn="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}"
TargetType="{x:Type Controls:ToggleSwitch}">
<Setter Property="Padding" Value="0 0 10 0" />
<Style.Triggers>
<Trigger Property="ContentDirection" Value="RightToLeft">
<Setter Property="Padding" Value="10 0 0 0" />
</Trigger>
</Style.Triggers>
</Style>
问题是这一行:
BasedOn="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}"
得到错误:
错误103无法解析资源“MahApps.Metro.Styles.ToggleSwitch.Win10”。
有什么建议 ?
使用NuGet安装MahApps(工具 - > NuGet包管理器 - > Visual Studio中的包管理器控制台):http://mahapps.com/guides/quick-start.html
并将Styles/Controls.ToggleSwitch.xaml
资源字典合并为:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ToggleSwitch.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="Custom.ToggleSwitch.Win10"
BasedOn="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}"
TargetType="{x:Type Controls:ToggleSwitch}">
<Setter Property="Padding" Value="0 0 10 0" />
<Style.Triggers>
<Trigger Property="ContentDirection" Value="RightToLeft">
<Setter Property="Padding" Value="10 0 0 0" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</Window.Resources>
如果您想使用MahApps提供的样式,您只需要修改ToggleSwitch以添加Style属性,如下所示:
<Controls:ToggleSwitch Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" />