MahApps.Metro——Quick Start
VS NuGet 패키지 관리 자 를 통 해 시각 적 으로 설치 하거나 다음 명령 을 사용 하여 패키지 관리 콘 솔 에 설치 할 수 있 습 니 다.
PM> Install-Package MahApps.Metro
Modifying the XAML file
After installing MahApps.Metro:
MainWindow.xaml
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
or
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
change <Window ...
tag to <Controls:MetroWindow ...
(remember to change the closing tag too!)
You should have something like this :
<Controls:MetroWindow x:Class="WpfApplication2.MainWindow"
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"
Title="MainWindow"
Height="350"
Width="525">
<!-- your content here -->
</Controls:MetroWindow>
Modifying the CodeBehind File
You'll also need to modify the MainWindow.xaml.cs
file so that the base class for MainWindow
matches the MetroWindow
class of the XAML file. To access MetroWindow
, add the following reference first.
// using statements...
using MahApps.Metro.Controls
public partial class MainWindow : MetroWindow
{
// ...
}
But in most cases you can just drop the base class (because this is a partial
class the XAML should take care of this): public partial class MainWindow
{
// ...
}
Using Built-In Styles
All of MahApp.Metro's resources are contained within separate resource dictionaries. In order for most of the controls to adopt the MahApps.Metro theme, you will need to add the following ResourceDictionaries to your App.xaml
.
App.xaml <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Make sure that all file names are Case Sensitive!
The end result will look something like this. If you want to know more about how the control works, more information can be found below.
What's a MetroWindow?
The default MetroWindow
is made up of a few components:
If you don't like the elements that are labelled, fear not, they're all optional. The titlebar is what sets MetroWindow
apart from rolling your own. ShowTitleBar="True|False"
The resize grip is not the only way to resize a MetroWindow
- all edges and corners can be gripped, but given a MetroWindow
doesn't have a noticeable window "chrome" like an aero window, the resize grip can help reassure users. Instead of using static images, the icons for minimize/maximize/close are a font called Marlett. To explain why this is so requires a walk down memory lane, or at least a visit to the Wikipedia article about it. You can even hide the icons on the title bar by setting the ShowIconOnTitleBar="True|False"
Customization
WindowButtonCommands WindowButtonCommands
are the minimize, maximize/restore, and close buttons. You can hide the buttons with ShowMinButton="True|False"
, ShowMaxRestoreButton="True|False"
and ShowCloseButton="True|False"
.
The visibility of the minimize and maximize/restore buttons are also effected by the ResizeMode
. If ResizeMode="NoResize"
the buttons are collapsed. If ResizeMode="CanMinimize"
the maximize/restore button is collapsed.
(Left-/Right-) WindowCommands
You can add your own controls to LeftWindowsCommands
or RightWindowsCommands
- by default, buttons have a style automatically applied to them to make them fit in with the rest of the WindowsCommands
. As of 0.9, you are no longer limited to just buttons, but any control. Be aware, you're responsible for styling anything other than buttons.
Including this within the <MetroWindow> ... </MetroWindow>
tag: <Controls:MetroWindow.RightWindowCommands>
<Controls:WindowCommands>
<Button Content="settings" />
<Button>
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20"
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill"
Visual="{StaticResource appbar_cupcake}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="4 0 0 0"
VerticalAlignment="Center"
Text="deploy cupcakes" />
</StackPanel>
</Button>
</Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>
Make sure to include the icons to get the cupcake.
Produces this window titlebar:
The foreground (link) colour of (Left-/Right-) WindowCommands
will always be white, unless the titlebar is disabled, in which case it will be the reverse of whatever theme you have selected. For example, using the White/Light theme, the foreground colour will be black.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java 스레드에서 start와 run 방법의 전면적인 해석사용자 정의 스레드 두 가지 방법 runnable 인터페이스의 실현 클래스를 사용자 정의한 다음thread를 구성합니다. 즉thread에 runnable 인터페이스 클래스를 전달합니다. newthread나thread...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.