简体   繁体   English

如何将颜色绑定到MahApps Metro资源?

[英]How to bind colors to MahApps Metro resource?

I'm using the MahApps Metro theme and everything mostly works fine except for fills. 我使用的是MahApps Metro主题,除填充外,其他所有东西都正常运行。 I would like to bind my fill color to the color in the theme and have it change according when changing between light/dark mode. 我想将填充色绑定到主题中的颜色,并根据在明暗模式之间进行更改来进行更改。 Does anyone know how to do this? 有谁知道如何做到这一点?

My App.xaml: 我的App.xaml:

<Application 
...>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                ...
                <!-- Accent and AppTheme setting -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

What I want to change: 我要更改的内容:

<Rectangle Fill="??????"">

Inside your Application.Resources you put: 在您的应用程序内部。您投入的资源:

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Dark">
        <SolidColorBrush x:Key="RectangleFill" Color="White"/>
    </ResourceDictionary>

    <ResourceDictionary x:Key="Light">
        <SolidColorBrush x:Key="RectangleFill" Color="Blue"/>
    </ResourceDictionary>
 </ResourceDictionary.ThemeDictionaries>

Then you should bind the Rectangle.Fill to the ThemeResource "RectangleFill" 然后,您应该将Rectangle.Fill绑定到ThemeResource“ RectangleFill”

<Rectangle Height="200" Width="400" Fill="{ThemeResource RectangleFill}"></Rectangle>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM