简体   繁体   English

wpf .netcoreapp 3.1 的 MahApps 中的样式“找不到资源 'MetroButton”

[英]Style “Cannot find resource 'MetroButton” in MahApps for wpf .netcoreapp 3.1

I am upgrading a wpf .netframework 4.7 app that uses MahApps.Metro style to a wpf .netcoreapp3.1 app.我正在将使用 MahApps.Metro 样式的 wpf .netframework 4.7 应用程序升级到 wpf .netcoreapp3.1 应用程序。 Afterthe migration I an getting:迁移后我得到:

System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.StaticResourceExtension' threw an exception. System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.StaticResourceExtension' 引发异常。

Exception: Cannot find resource named 'MetroButton'.例外:找不到名为“MetroButton”的资源。 Resource names are case sensitive.资源名称区分大小写。

<ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Button.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Styles.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />

            <ResourceDictionary>
                <!--Button-->
                <Style x:Key="SmallButtonStyle" TargetType="Button" BasedOn="{StaticResource MetroButton}">
                    <Setter Property="Height" Value="40" />
                    <Setter Property="Width" Value="200" />
                    <Setter Property="Margin" Value="5,2" />
                    <Setter Property="FontSize" Value="14" />
                </Style>
                <Style x:Key="StandardButtonStyle" TargetType="Button" BasedOn="{StaticResource MetroButton}">
                    <Setter Property="Height" Value="50" />
                    <Setter Property="Width" Value="350" />
                    <Setter Property="Margin" Value="10,5" />
                    <Setter Property="FontSize" Value="20" />
                </Style>

This worked with MahApps.Metro version 1.65 under .netframework 4.7 but with MahApps.Metro 2.0.0-alpha0748 I get the exception.这适用于 .netframework 4.7 下的 MahApps.Metro 版本 1.65,但使用 MahApps.Metro 2.0.0-alpha0748 我得到了例外。

Solution: change MetroButton to MahApps.Styles.Button解决方案:将MetroButton更改为MahApps.Styles.Button

 <Style x:Key="SmallButtonStyle" TargetType="Button" BasedOn="{StaticResource MahApps.Styles.Button}">
                    <Setter Property="Height" Value="40" />
                    <Setter Property="Width" Value="200" />
                    <Setter Property="Margin" Value="5,2" />
                    <Setter Property="FontSize" Value="14" />
                </Style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM