Avalonia框架下使用Material中NavigationDrawer控件和ColorZone控件

从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>
Avalonia是一种用于构建跨平台用户界面的开源框架。导航控件Avalonia的一种重要控件,用于在不同页面之间进行导航操作。 Avalonia的导航控件允许我们在应用程序创建多个页面,并且能够在这些页面之间进行平滑的切换。导航控件提供了一种结构化的方式来组织和管理应用程序的不同界面。通过导航控件,我们可以通过简单的命令或代码逻辑来实现页面的导航和跳转。 导航控件通常由两个主要组件组成:导航器和页面容器。导航器负责维护当前页面的状态,并提供导航操作的方法和事件。页面容器用于显示和管理不同的页面。当我们进行页面导航时,导航器会负责加载、显示和销毁页面。 对于使用Avalonia导航控件的应用程序,我们可以在页面间使用导航器提供的方法来切换页面,这样可以实现应用程序的整体流程控制。例如,我们可以使用导航控件在登录页面和主页面之间进行导航,或者在主页面的不同子页面之间进行导航。 此外,Avalonia导航控件还可以与其他控件一起使用,以实现更复杂的用户界面。例如,我们可以将导航控件和菜单控件结合使用,以创建具有导航功能的应用程序菜单。我们也可以将导航控件和数据绑定一起使用,以实现基于数据驱动的页面导航。 总而言之,Avalonia导航控件是一种实用的工具,可以帮助我们在Avalonia应用程序有效地管理和导航页面,提供良好的用户体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值