質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
.NET Core

.NET Coreは、マネージソフトウェアフレームワークでオープンソースで実装されています。クロスプラットフォームを前提に考えられており、Windows/Mac/Linuxで動くアプリケーションを作成することが可能です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

解決済

1回答

5776閲覧

MaterialDesignThemes.MahAppsでのエラーに関して

kawauso

総合スコア56

.NET Core

.NET Coreは、マネージソフトウェアフレームワークでオープンソースで実装されています。クロスプラットフォームを前提に考えられており、Windows/Mac/Linuxで動くアプリケーションを作成することが可能です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

1グッド

0クリップ

投稿2020/08/21 00:19

編集2020/08/21 01:16

前提・実現したいこと

WPFで作成しているアプリケーションに
Material Design In XAML Toolkit + Mahapps
を適用したいと思っております。
こちらを参考に適用しました。
ただ、下記のようなエラーメッセージが出力されます。
(参考にしたページの方がソースをアップロードしてくださっていますが、それも同様のエラーが出力されます。)

発生している問題・エラーメッセージ

System.Windows.ResourceDictionary Warning: 9 : Resource not found System.Windows.ResourceDictionary Warning: 9 : Resource not found System.Windows.ResourceDictionary Warning: 9 : Resource not found System.Windows.ResourceDictionary Warning: 9 : Resource not found System.Windows.ResourceDictionary Warning: 9 : Resource not found System.Windows.ResourceDictionary Warning: 9 : Resource not found

該当のソースコード

App.xaml

xmal

1<Application x:Class="WpfApp1.App" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" 5 xmlns:local="clr-namespace:WpfApp1" 6 StartupUri="MainWindow.xaml"> 7 <Application.Resources> 8 <ResourceDictionary> 9 <ResourceDictionary.MergedDictionaries> 10 <materialDesign:BundledTheme 11 BaseTheme="Light" 12 PrimaryColor="Cyan" 13 SecondaryColor="Amber" /> 14 <!-- MahApps Integration --> 15 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 16 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 17 18 <!-- MaterialDesign Control Theme --> 19 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" /> 20 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> 21 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Flipper.xaml" /> 22 23 <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />--> 24 <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />--> 25 </ResourceDictionary.MergedDictionaries> 26 <!-- Custom Color --> 27 <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#e5ffff" /> 28 <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#000000" /> 29 <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#b2ebf2" /> 30 <SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#000000" /> 31 <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#007c91" /> 32 <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF" /> 33 34 <!-- MahApps Brushes --> 35 <SolidColorBrush x:Key="HighlightBrush" Color="{DynamicResource Primary700}" /> 36 <SolidColorBrush x:Key="AccentBaseColorBrush" Color="{DynamicResource Primary600}" /> 37 <SolidColorBrush x:Key="AccentColorBrush" Color="{DynamicResource Primary500}" /> 38 <SolidColorBrush x:Key="AccentColorBrush2" Color="{DynamicResource Primary400}" /> 39 <SolidColorBrush x:Key="AccentColorBrush3" Color="{DynamicResource Primary300}" /> 40 <SolidColorBrush x:Key="AccentColorBrush4" Color="{DynamicResource Primary200}" /> 41 <SolidColorBrush x:Key="WindowTitleColorBrush" Color="{DynamicResource Primary700}" /> 42 <SolidColorBrush x:Key="AccentSelectedColorBrush" Color="{DynamicResource Primary500Foreground}" /> 43 <LinearGradientBrush x:Key="ProgressBrush" StartPoint="1.002,0.5" EndPoint="0.001,0.5"> 44 <GradientStop Offset="0" Color="{DynamicResource Primary700}" /> 45 <GradientStop Offset="1" Color="{DynamicResource Primary300}" /> 46 </LinearGradientBrush> 47 <SolidColorBrush x:Key="CheckmarkFill" Color="{DynamicResource Primary500}" /> 48 <SolidColorBrush x:Key="RightArrowFill" Color="{DynamicResource Primary500}" /> 49 <SolidColorBrush x:Key="IdealForegroundColorBrush" Color="{DynamicResource Primary500Foreground}" /> 50 <SolidColorBrush 51 x:Key="IdealForegroundDisabledBrush" 52 Opacity="0.4" 53 Color="{DynamicResource Primary500}" /> 54 <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchBrush.Win10" Color="{DynamicResource Primary500}" /> 55 <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchMouseOverBrush.Win10" Color="{DynamicResource Primary400}" /> 56 <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.ThumbIndicatorCheckedBrush.Win10" Color="{DynamicResource Primary500Foreground}" /> 57 </ResourceDictionary> 58 </Application.Resources> 59</Application>

MainWindow.xaml

xaml

1<metro:MetroWindow x:Class="WpfApp1.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:material="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf" 7 xmlns:local="clr-namespace:WpfApp1" 8 xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" 9 Background="{DynamicResource MaterialDesignPaper}" 10 BorderThickness="3" 11 FontFamily="{material:MaterialDesignFont}" 12 GlowBrush="{DynamicResource AccentColorBrush}" 13 TextElement.FontSize="14" 14 TextElement.FontWeight="Medium" 15 TextElement.Foreground="{DynamicResource MaterialDesignBody}" 16 mc:Ignorable="d" 17 Title="MainWindow" Height="450" Width="800"> 18 <StackPanel> 19 <Button Content="Button1"/> 20 <TextBlock Text="TextBlock"/> 21 <material:PackIcon Kind="Abc" Width="30" Height="30"/> 22 </StackPanel> 23</metro:MetroWindow>

MainWindow.xaml

c#

1using MahApps.Metro.Controls; 2 3namespace WpfApp1 4{ 5 public partial class MainWindow : MetroWindow 6 { 7 public MainWindow() 8 { 9 InitializeComponent(); 10 } 11 } 12} 13

試したこと

エラーメッセージで検索した際に「DynamicResource」を「StaticResource」に変更すればよいとあったので全て変更しましたが、解決しませんでした。

MahAppsを無効化?したところエラーは出力されなくなりました。が
デザイン上、MahAppsは有効化したいと思っております。解決方法をご存知の方はご教授お願いいたします。

xaml

1<Window x:Class="WpfApp1.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:material="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf" 7 xmlns:local="clr-namespace:WpfApp1" 8 xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" 9 Background="{DynamicResource MaterialDesignPaper}" 10 BorderThickness="3" 11 FontFamily="{material:MaterialDesignFont}" 12 TextElement.FontSize="14" 13 TextElement.FontWeight="Medium" 14 TextElement.Foreground="{DynamicResource MaterialDesignBody}" 15 mc:Ignorable="d" 16 Title="MainWindow" Height="450" Width="800"> 17 <StackPanel> 18 <Button Content="Button1"/> 19 <TextBlock Text="TextBlock"/> 20 <material:PackIcon Kind="Abc" Width="30" Height="30"/> 21 </StackPanel> 22</Window>

c#

1using System.Windows; 2 3namespace WpfApp1 4{ 5 public partial class MainWindow : Window 6 { 7 public MainWindow() 8 { 9 InitializeComponent(); 10 } 11 } 12} 13

補足情報(FW/ツールのバージョンなど)

VisualStudio 2019
C#
.Net Core 3.1
WPF
MaterialDesignThemes.MahApps 0.1.4(NuGet)

TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

実行はできるんですよね?
実行時にそのワーニングが出て気持ちが悪い(というか適応されない部分があるはず)ということですね?

soi013/MaterialDesignThemesV3Demo
をダウンロードして確認しました。確かに出ます。
閉じるボタンあたりがおかしいです(色も変だし、さわるとワーニングが増える)

以下やったこと

NuGetを一通りバージョンアップしてみる(変わらず)
仕方がないのでドキュメントを見る。Quick Start · MahApps/MahApps.Metro Wiki
1行足りない気がするので追加してみる。

どうやら当たりのようです!
色もそれっぽくなりましたし、ワーニングも消えました(これで万事解決なのかはわかりません^^;

xml

1 <!-- MahApps Integration --> 2 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 3 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 4 <!-- これを追加 --> 5 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" /> 6 7 <!-- MaterialDesign Control Theme --> 8 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" /> 9 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> 10 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Flipper.xaml" /> 11 <!-- 以下略 -->

MahApps.Metro v2はようやく出た新バージョンで、かなりの変更があるので注意が必要ですね。

MahAppsMetro integration · MaterialDesignInXAML/MaterialDesignInXamlToolkit Wiki
こちらのドキュメントは変更に追いついていないですね^^;

投稿2020/08/21 08:50

編集2023/07/23 04:39
TN8001

総合スコア9326

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kawauso

2020/08/21 09:28

ご回答ありがとうございます。 > 実行時にそのワーニングが出て気持ちが悪い(というか適応されない部分があるはず)ということですね? その通りです。 提示していただいた方法で解決しました! MahAppsのドキュメントは確認できていなかったので目を通しておきたいと思います。以後気を付けます。 助かりました。ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問