![](/img/trans.png)
[英]Style “Cannot find resource 'MetroCheckBox'” in MahApps
[英]Style “Cannot find resource 'MetroButton” in MahApps for wpf .netcoreapp 3.1
我正在將使用 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 我得到了例外。
解決方案:將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.