【问题标题】:Style “Cannot find resource 'MetroButton” in MahApps for wpf .netcoreapp 3.1在 wpf .netcoreapp 3.1 的 MahApps 中样式“找不到资源 'MetroButton”
【发布时间】:2020-04-23 14:23:57
【问题描述】:

我正在将使用 MahApps.Metro 样式的 wpf .netframework 4.7 应用程序升级到 wpf .netcoreapp3.1 应用程序。迁移后我得到:

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

异常:找不到名为“MetroButton”的资源。资源名称区分大小写。

<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>

这适用于 .netframework 4.7 下的 MahApps.Metro 版本 1.65,但使用 MahApps.Metro 2.0.0-alpha0748 我得到了例外。

【问题讨论】:

    标签: c# wpf mahapps.metro app.xaml netcoreapp3.1


    【解决方案1】:

    解决方法:将 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>
    

    【讨论】:

      猜你喜欢
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      相关资源
      最近更新 更多