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

问题描述 投票:0回答:1

我正在使用MahApps Metro主题,除了填充之外,一切都很好。我想将填充颜色绑定到主题中的颜色,并根据明暗模式之间的变化进行更改。有谁知道如何做到这一点?

我的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>

我想改变什么:

<Rectangle Fill="??????"">
c# .net wpf xaml mahapps.metro
1个回答
1
投票

你在Application.Resources里面放了:

<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>

然后你应该将Rectangle.Fill绑定到ThemeResource“RectangleFill”

<Rectangle Height="200" Width="400" Fill="{ThemeResource RectangleFill}"></Rectangle>
© www.soinside.com 2019 - 2024. All rights reserved.