C# - マテリアル デザインのアイコンとテキストを原色に変更する

okwaves2024-01-25  8

マテリアル デザインを使用するのは初めてで、すべてが非常に効果的に機能している一方で、アイコンの色に少し混乱しました。

私の App.xaml には次のリソース ディクショナリがあります。

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Grey.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Yellow.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

フォームにはアイコンとテキストブロックがあります。

        <DockPanel>
            <materialDesign:PackIcon x:Name="iconWarning" Width="25" Height="25" Margin="5" Kind="Warning" Foreground="OrangeRed" />
            <TextBlock x:Name="lblWarning" Text="Warning" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" Padding="5" Foreground="OrangeRed"/>
        </DockPanel>

ただし、私の C# コードには、使用中のテーマを変更し、主色と副色も変更できるメソッドがあります。ただし、カラーゾーンで設定する方法と同じように、テキストブロックとアイコンで原色を使用するように設定するにはどうすればよいですか。たとえば、Foreground="OrangeRed";; を使用する必要があるモードとは反対のモードを使用します。

Mode="PrimaryMid"


------------------------

プライマリ* ブラシ リソースはここにあります:

<materialDesign:PackIcon x:Name="iconWarning" Width="25" Height="25" Margin="5" Kind="Warning"
                         Foreground="{StaticResource PrimaryHueMidBrush}" />
<TextBlock x:Name="lblWarning" Text="Warning" HorizontalAlignment="Left" VerticalAlignment="Center"
           Margin="5" Padding="5"
           Foreground="{StaticResource PrimaryHueMidBrush}" />

総合生活情報サイト - OKWAVES
総合生活情報サイト - OKWAVES
生活総合情報サイトokwaves(オールアバウト)。その道のプロ(専門家)が、日常生活をより豊かに快適にするノウハウから業界の最新動向、読み物コラムまで、多彩なコンテンツを発信。