ฉันกำลังทำงานกับแอป WPF ที่ใช้ MahApps MetroWindow เป็นหน้าต่างหลัก ฉันใช้การจัดสไตล์บนปุ่มย่อเล็กสุด / ขยายใหญ่สุดและปิดที่สร้างใน MetroWindow ขณะนี้สไตล์มีลักษณะดังนี้: (สไตล์ขยายใหญ่สุดและปิดคล้ายกัน)
<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>
สไตล์นั้นใช้งานได้ตามที่คาดไว้ แต่ฉันพลาดสิ่งหนึ่งไป:
- เมื่อแอปพลิเคชันสูญเสียโฟกัส ฉันต้องการตั้งค่าพื้นหลังของปุ่มเหล่านั้นให้เป็นสีเทาเหมือนกับส่วนอื่นๆ ของแอปพลิเคชัน ขณะนี้ปุ่มต่างๆ ยังคงเชื่อมโยงกับทรัพยากร
PrimaryHueMidBrush
แม้ว่าฉันจะสามารถเปลี่ยนพื้นหลังของปุ่มในเหตุการณ์นี้ได้ แต่ฉันไม่พบปุ่มปิดขั้นต่ำสุดใน 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");
}
มีวิธีการตั้งค่าพื้นหลังของปุ่มเหล่านั้นเมื่อแอปพลิเคชันสูญเสียโฟกัส (window_deactivated) หรือไม่?