Saya sedang mengerjakan aplikasi WPF yang menggunakan MahApps MetroWindow sebagai jendela utama. Saya menggunakan gaya pada tombol Minimalkan/Maksimalkan dan Tutup yang dibuat di MetroWindow. Gaya saat ini terlihat sebagai berikut: (gaya maksimalkan dan tutup serupa)
<Controls:MetroWindow.WindowMinButtonStyle>
<Style TargetType="Button">
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource BlackBrush}"/>
<Setter Property="Width" Value="35"/>
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Padding"
Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid"
Background="{TemplateBinding Background}">
<ContentPresenter x:Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
RecognizesAccessKey="True"
Opacity="0.75" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="contentPresenter"
Property="Opacity"
Value="1" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="False">
<Setter TargetName="contentPresenter"
Property="Opacity"
Value=".5" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="#ADADAD" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls:MetroWindow.WindowMinButtonStyle>
Gayanya sendiri berfungsi seperti yang diharapkan tetapi saya melewatkan satu hal:
- Ketika aplikasi kehilangan fokus saya ingin mengatur latar belakang tombol-tombol itu menjadi abu-abu seperti aplikasi lainnya. Saat ini tombol-tombol tersebut masih terikat pada sumber daya
PrimaryHueMidBrush
.
Saya pikir saya dapat mengubah latar belakang tombol di acara ini tetapi saya tidak dapat menemukan tombol tutup min maks di MetroWindow.
private void Window_Deactivated(object sender, EventArgs e)
{
SolidColorBrush gray = new SolidColorBrush(Colors.Gray);
StatusBar.Background = gray;
}
private void Window_Activated(object sender, EventArgs e)
{
StatusBar.Background = (SolidColorBrush)FindResource("PrimaryHueMidBrush");
}
Apakah ada cara untuk mengatur latar belakang tombol-tombol tersebut ketika aplikasi kehilangan fokus (window_deactivated)?