3

我在这里找到了这种风格并将其添加到我的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”。

有什么建议么 ?

4

2 回答 2

4

使用 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>
于 2017-03-13T13:16:42.677 回答
3

如果您想使用 MahApps 提供的样式,您只需修改 ToggleSwitch 以添加 Style 属性,如下所示:

<Controls:ToggleSwitch Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" />
于 2019-02-20T14:44:23.813 回答