C# 如何设置MahApps窗网格的样式?

C# 如何设置MahApps窗网格的样式?,c#,wpf,xaml,data-binding,mahapps.metro,C#,Wpf,Xaml,Data Binding,Mahapps.metro,我正在为我的WPF应用程序使用Mahapps UI toolkit,我需要放置在MetroWindow中的网格,以便在应用程序不像MetroWindow那样处于活动状态时更改其颜色。我尝试了几种解决方案,但都没有成功: <Grid Background="{DynamicResource AccentColorBrush}" > <TextBlock Text="Test" Foreground="#FFFFFF" VerticalAlignm

我正在为我的WPF应用程序使用Mahapps UI toolkit,我需要放置在MetroWindow中的网格,以便在应用程序不像MetroWindow那样处于活动状态时更改其颜色。我尝试了几种解决方案,但都没有成功:

<Grid Background="{DynamicResource AccentColorBrush}" >
                <TextBlock Text="Test" Foreground="#FFFFFF"  VerticalAlignment="Center" Padding="10,0,0,0"/>
</Grid>

此解决方案将网格颜色设置为AccentColorBrush

<Grid Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=controls:MetroWindow}, Path=WindowTitleBrush}" >
                <TextBlock Text="Test" Foreground="#FFFFFF"  VerticalAlignment="Center" Padding="10,0,0,0"/>
</Grid>

我还可以使用NonActivieWindowitLebrush属性将网格颜色设置为非活动

<Grid Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=controls:MetroWindow}, Path=NonActiveWindowTitleBrush}" >
                    <TextBlock Text="Test" Foreground="#FFFFFF"  VerticalAlignment="Center" Padding="10,0,0,0"/>
</Grid>

我会感谢你的帮助

尊敬的Dmitry

试试这个:

<Controls:MetroWindow x:Class="MahApps.Metro.Application12.MainWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
                  xmlns:Custom="http://metro.mahapps.com/winfx/xaml/shared" 
                  Title="MainWindow"
                  Height="350" 
                  Width="525">

<Controls:MetroWindow.Resources>

    <Style x:Key="GridStyle1" TargetType="{x:Type Grid}">
        <Setter Property="Background" Value="{StaticResource AccentColorBrush}"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}" Value="False">
                <Setter Property="Background"  Value="{StaticResource GrayBrush3}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

</Controls:MetroWindow.Resources>

<Grid x:Name="grid1" Margin="50" HorizontalAlignment="Center" VerticalAlignment="Center" Height="232" Width="409" Style="{StaticResource GridStyle1}">

    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="32" Text="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"/>

</Grid>


是的,我已经做了同样的。我认为一些动态画笔是可用的,等等。无论如何,非常感谢!也许有一个。。。。发布一个与此解决方案相关的后续问题,并解释虽然这是可行的,但您正在使用动态笔刷寻找替代解决方案。我不知道,但其他人可能知道。