[英]WPF MahApps Change style of Window notworking for elements inside its UserControl
[英]How To Style MahApps Window Grid?
我正在為我的WPF應用程序使用Mahapps UI工具包,我需要放置在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>
我還可以使用NonActiveWindowTitleBrush屬性將網格顏色設置為非活動狀態
<Grid Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=controls:MetroWindow}, Path=NonActiveWindowTitleBrush}" >
<TextBlock Text="Test" Foreground="#FFFFFF" VerticalAlignment="Center" Padding="10,0,0,0"/>
</Grid>
我會感謝任何幫助。
此致,德米特里
嘗試這個:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.