从GitHub中clone项目查看代码和样式。
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:Material.Avalonia.Demo.Models"
xmlns:pages="clr-namespace:Material.Avalonia.Demo.Pages"
xmlns:pages1="clr-namespace:Material.Demo.Pages"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Styles>
<Style Selector="TextBlock.Subheadline">
<Setter Property="Margin" Value="0, 16" />
</Style>
<Style Selector="TextBlock.Subheadline2">
<Setter Property="Margin" Value="0, 8" />
</Style>
<Style Selector="TextBlock.Content">
<Setter Property="Margin" Value="0, 4" />
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
</UserControl.Styles>
<UserControl.DataTemplates>
<DataTemplate DataType="models:Sample2Model">
<StackPanel>
<TextBlock TextAlignment="Center">Your lucky number:</TextBlock>
<TextBlock Classes="Body1"
Text="{Binding Number}"
TextAlignment="Center" />
<Button Margin="0,8,0,0" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
THANKS, CLOSE
</Button>
</StackPanel>
</DataTemplate>
</UserControl.DataTemplates>
<dialogHostAvalonia:DialogHost Identifier="MainDialogHost">
<controls:SnackbarHost HostName="Root" TemplateApplied="TemplatedControl_OnTemplateApplied">
<controls:NavigationDrawer Name="LeftDrawer"
Classes="permanent"
LeftDrawerOpened="{Binding ElementName=NavDrawerSwitch,
Path=IsChecked,
Mode=TwoWay}">
<controls:NavigationDrawer.LeftDrawerContent>
<ScrollViewer>
<StackPanel>
<controls:ColorZone Height="180" Mode="Accent">
<StackPanel>
<Image Width="96"
Height="120"
Margin="0,0,0,-8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
PointerPressed="MaterialIcon_OnPointerPressed"
Source="avares://Material.Avalonia.Demo/Assets/FavIcon_128x.png" />
<TextBlock HorizontalAlignment="Center"
Classes="Headline6"
Text="Material Design" />
<TextBlock HorizontalAlignment="Center"
Classes="Subtitle1"
Text="with AvaloniaUI" />
</StackPanel>
</controls:ColorZone>
<ListBox Name="DrawerList"
Classes="NoScroll"
Focusable="{Binding ElementName=LeftDrawer,
Path=LeftDrawerOpened}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Height" Value="48" />
<Setter Property="Padding" Value="16,0" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</ListBox.Styles>
<ListBoxItem>Home</ListBoxItem>
<ListBoxItem>Buttons</ListBoxItem>
<ListBoxItem>Toggles</ListBoxItem>
<ListBoxItem>Fields</ListBoxItem>
<ListBoxItem>ComboBoxes</ListBoxItem>
<ListBoxItem>Material Icons</ListBoxItem>
<ListBoxItem>Colors</ListBoxItem>
<ListBoxItem>Sliders</ListBoxItem>
<ListBoxItem>Progress indicators</ListBoxItem>
<ListBoxItem>Lists</ListBoxItem>
<ListBoxItem>Expanders</ListBoxItem>
<ListBoxItem>ColorZones</ListBoxItem>
<ListBoxItem>Dialogs</ListBoxItem>
<ListBoxItem>Snackbar</ListBoxItem>
<ListBoxItem>ScrollViewer</ListBoxItem>
<ListBoxItem>SideSheet</ListBoxItem>
<ListBoxItem>TabControls</ListBoxItem>
<ListBoxItem>TreeViews</ListBoxItem>
<ListBoxItem>Card</ListBoxItem>
<ListBoxItem>Typography</ListBoxItem>
<ListBoxItem>Date/Time pickers</ListBoxItem>
<ListBoxItem>Shadows</ListBoxItem>
</ListBox>
</StackPanel>
</ScrollViewer>
</controls:NavigationDrawer.LeftDrawerContent>
<DockPanel LastChildFill="true">
<controls:ColorZone Name="PART_AppBarContainer"
Height="56"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
DockPanel.Dock="Top"
Mode="PrimaryMid"
ZIndex="1">
<Grid Margin="16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="32" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="32" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ToggleButton Name="NavDrawerSwitch"
Width="32"
Height="32"
Padding="4"
Theme="{StaticResource MaterialFlatButton}">
<avalonia:MaterialIcon Width="24"
Height="24"
Kind="Menu" />
</ToggleButton>
<TextBlock Grid.Column="2"
VerticalAlignment="Center"
Classes="Headline6"
Text="Material.Avalonia Demo" />
<Menu Grid.Column="4"
Height="32"
Margin="0"
Padding="0">
<MenuItem Width="32"
Height="32"
Header="{avalonia:MaterialIconExt DotsVertical,
Size=24}">
<MenuItem Click="HelloButtonMenuItem_OnClick" Header="Hello!">
<MenuItem.Icon>
<avalonia:MaterialIcon Width="24"
Height="24"
Kind="Hand" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Click="ConnectToNetworkMenuItem_OnClick" Header="Connect to network">
<MenuItem.Icon>
<avalonia:MaterialIcon Width="24"
Height="24"
Kind="RocketLaunch" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Action 1" />
<MenuItem Header="Action 2" />
<MenuItem Header="Action 3" />
<Separator />
<MenuItem Click="GoodbyeButtonMenuItem_OnClick" Header="Goodbye">
<MenuItem.Icon>
<avalonia:MaterialIcon Width="24"
Height="24"
Kind="ExitRun" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</controls:ColorZone>
<ScrollViewer Name="mainScroller"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
DockPanel.Dock="Top"
HorizontalScrollBarVisibility="Disabled">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Carousel Name="PageCarousel" HorizontalAlignment="Stretch">
<Carousel.Styles>
<Style Selector="Carousel#PageCarousel:not(.no-transitions)">
<Setter Property="PageTransition">
<PageSlide SlideInEasing="CircularEaseOut"
SlideOutEasing="CircularEaseOut"
Duration="0.25" />
</Setter>
</Style>
</Carousel.Styles>
<!-- Main page -->
<pages:Home />
<!-- Buttons -->
<pages:ButtonsDemo />
<!-- Toggles -->
<pages:TogglesDemo />
<!-- Fields -->
<pages:FieldsDemo />
<!-- ComboBoxes -->
<pages:ComboBoxesDemo />
<!-- Icons -->
<pages:IconsDemo />
<!-- Colors -->
<pages:ColorsDemo />
<!-- Sliders -->
<pages:SlidersDemo />
<!-- Progress indicators -->
<pages:ProgressIndicatorDemo />
<!-- Lists -->
<pages:ListsDemo />
<!-- Expanders -->
<pages:ExpandersDemo />
<!-- ColorZones -->
<pages:ColorZonesDemo />
<!-- Dialogs -->
<pages:DialogDemo />
<!-- Snackbar -->
<pages1:SnackbarDemo />
<!-- ScrollViewer -->
<pages:ScrollViewerDemo />
<!-- SideSheet -->
<pages:SideSheetDemo />
<!-- TabControls -->
<pages:TabsDemo />
<!-- TreeViews -->
<pages:TreeViewsDemo />
<!-- Card -->
<pages:CardsDemo />
<!-- Typography -->
<pages:TypographyDemo />
<!-- Pickers -->
<pages:DateTimePickerDemo />
<!-- Shadows -->
<pages:NotReadyDemo />
</Carousel>
</Border>
</ScrollViewer>
</DockPanel>
</controls:NavigationDrawer>
</controls:SnackbarHost>
</dialogHostAvalonia:DialogHost>
</UserControl>
更改一下
<Window
x:Class="C1_For_Linux.SettingView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:material="clr-namespace:Material.Styles;assembly=Material.Styles"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
xmlns:vm="using:C1_For_Linux.ViewModels"
Title="SettingView"
d:DesignHeight="768"
d:DesignWidth="1024"
x:DataType="vm:SettingViewModel"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{StaticResource MyFont}"
TextElement.FontWeight="Regular"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
WindowStartupLocation="CenterScreen"
WindowState="Normal"
mc:Ignorable="d">
<!--<Window.Resources>
<FontFamily x:Key="MyFontWindow">/Assets/Fonts/msyh.ttf#Microsoft YaHei</FontFamily>
</Window.Resources>-->
<Window.Styles>
<Style Selector="TextBlock.Subheadline">
<Setter Property="Margin" Value="0, 16" />
</Style>
<Style Selector="TextBlock.Subheadline2">
<Setter Property="Margin" Value="0, 8" />
</Style>
<Style Selector="TextBlock.Content">
<Setter Property="Margin" Value="0, 4" />
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
<Style Selector="TabItem">
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
<Setter Property="FontSize" Value="16" />
</Style>
<Style Selector="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="TextBox">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="ToggleButton">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="Button">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="ComboBox">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="ComboBoxItem">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
<Style Selector="ListBoxItem">
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
</Window.Styles>
<Grid>
<controls:NavigationDrawer
Name="LeftDrawer"
Classes="permanent"
LeftDrawerOpened="{Binding ElementName=NavDrawerSwitch, Path=IsChecked, Mode=TwoWay}">
<!-- 左侧抽屉内容 -->
<controls:NavigationDrawer.LeftDrawerContent>
<StackPanel>
<controls:ColorZone Height="100" Mode="Accent">
<StackPanel>
<TextBlock
Margin="0,15,0,5"
HorizontalAlignment="Center"
Classes="Headline6"
Text="温馨提示" />
<TextBlock
HorizontalAlignment="Center"
Classes="Subtitle1"
Text="更新设置后,请记得保存!" />
</StackPanel>
</controls:ColorZone>
<!--由于使用prism框架需要Command驱动事件,故抛弃listbox方式使用button控件代替-->
<!--<ListBox
Name="DrawerList"
Classes="NoScroll"
Focusable="{Binding ElementName=LeftDrawer, Path=LeftDrawerOpened}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Height" Value="48" />
<Setter Property="Padding" Value="16,0" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontFamily" Value="{StaticResource MyFont}" />
</Style>
</ListBox.Styles>
<ListBoxItem>设置</ListBoxItem>
<ListBoxItem>刻度</ListBoxItem>
<ListBoxItem>维护</ListBoxItem>
<ListBoxItem>记录</ListBoxItem>
<ListBoxItem>关于</ListBoxItem>
</ListBox>-->
<StackPanel Orientation="Vertical">
<Button
Height="48"
Padding="16,0"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Background="White"
Command="{Binding OpenViewCommand}"
CommandParameter="SettingHomeView"
Content="设置"
FontSize="18"
Foreground="Black" />
<Button
Height="48"
Padding="16,0"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Background="White"
Command="{Binding OpenViewCommand}"
CommandParameter="CalibrationView"
Content="刻度"
FontSize="18"
Foreground="Black" />
<Button
Height="48"
Padding="16,0"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Background="White"
Command="{Binding OpenViewCommand}"
CommandParameter="MaintenanceView"
Content="维护"
FontSize="18"
Foreground="Black" />
<Button
Height="48"
Padding="16,0"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Background="White"
Command="{Binding OpenViewCommand}"
CommandParameter="HistoryDataView"
Content="记录"
FontSize="18"
Foreground="Black" />
<Button
Height="48"
Padding="16,0"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Background="White"
Command="{Binding OpenViewCommand}"
CommandParameter="AboutView"
Content="关于"
FontSize="18"
Foreground="Black" />
</StackPanel>
</StackPanel>
</controls:NavigationDrawer.LeftDrawerContent>
<DockPanel>
<controls:ColorZone
Name="PART_AppBarContainer"
Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
DockPanel.Dock="Top"
Mode="PrimaryMid"
ZIndex="1">
<Grid Margin="16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- 触发左侧抽屉和标题 -->
<ToggleButton
Name="NavDrawerSwitch"
Width="32"
Height="32"
Padding="0"
IsChecked="False"
Theme="{StaticResource MaterialFlatButton}">
<icons:MaterialIcon
Width="24"
Height="24"
Kind="Menu" />
</ToggleButton>
<TextBlock
Grid.Column="2"
VerticalAlignment="Center"
Classes="Headline6"
Text="菜单" />
<!-- 右侧更多操作 -->
<Menu
Grid.Column="4"
Height="32"
Margin="0"
Padding="0">
<MenuItem
Width="32"
Height="32"
Header="{icons:MaterialIconExt DotsVertical,
Size=24}">
<MenuItem FontFamily="{StaticResource MyFont}">
<MenuItem.Header>
您好,欢迎使用本系统
</MenuItem.Header>
<MenuItem.Icon>
<icons:MaterialIcon
Width="24"
Height="24"
Kind="Hand" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Connect to network">
<MenuItem.Icon>
<icons:MaterialIcon
Width="24"
Height="24"
Kind="RocketLaunch" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Name="MovetoMainwindow" Header="进入运行状态" />
<MenuItem Header="修改密码" />
<MenuItem Header="开始自检" />
<Separator />
<MenuItem FontFamily="{StaticResource MyFont}" Header="退出系统">
<MenuItem.Icon>
<icons:MaterialIcon
Width="24"
Height="24"
Kind="ExitRun" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</controls:ColorZone>
<ContentControl prism:RegionManager.RegionName="MainRegion" />
</DockPanel>
</controls:NavigationDrawer>
</Grid>
</Window>