我正在升级一个使用MahApps.Metro风格的wpf.netframework4.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' threw an exception: 找不到名为'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中,我得到了这个异常。
解决方案:改变 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>