Change Background in MetroWindow (MahApp)

为君一笑 提交于 2019-12-11 18:15:49

问题


How can I change the background of a MetroWindow?

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
                xmlns:Converters="clr-namespace:MahApps.Metro.Converters"
                xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">

<Style  BasedOn="{StaticResource {x:Type Controls:MetroWindow}}" TargetType="Controls:MetroWindow">
    <Setter Property="Background" Value="LightGray" />
    <Setter Property="BorderBrush" Value="#FFB9B9B9" />
    <Setter Property="BorderThickness" Value="0,1,0,0" />
</Style>


回答1:


create a style with a key (and put the style in your App.xaml or in a resource dictionary and put this in your App.xaml)

<Style x:Key="CustomMetroWindowStyle" TargetType="{x:Type Controls:MetroWindow}">
  <Setter Property="Background"
          Value="LightGray" />
  <Setter Property="BorderBrush"
          Value="#FFB9B9B9" />
  <Setter Property="BorderThickness"
          Value="0,1,0,0" />
</Style>

and use it like this

<Controls:MetroWindow x:Class="MetroDemo.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      Style="{DynamicResource CustomMetroWindowStyle}">
</Controls:MetroWindow>


来源:https://stackoverflow.com/questions/21745367/change-background-in-metrowindow-mahapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!