WPF之工具栏菜单栏功能区。

1,菜单栏,工具栏,状态栏。

1.1,Menu中可添加菜单分隔条<Separator></Separator>作为分割线,使用Separator可以通过改变其template来自定义,Separator是无焦点的,如果简单的在MenuItem中添加一个textBlock它是可以有焦点的

1.2,ToolBar没有ToolBarItem,ToolBar会将添加到其中的Button,CheckBox,Combobox样式进行修改.

1.3,通过附加属性ToolBar.OverFlowMode来设置该项的溢出方式

1.4,ToolBarTray.Band:确定工具栏放在哪一栏中(最顶部的一栏索引为0),BandIndex属性明确设置一栏中什么位置放置工具栏.

1.5,ToolBarTray.Orientation:设置工具栏方向

1.6,示例:

XML 复制代码
<Window x:Class="目录样例.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:目录样例"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <DockPanel LastChildFill="False">
        <Menu DockPanel.Dock="Top" >
            <MenuItem Header="File(_F)">
                <MenuItem Command="{x:Static ApplicationCommands.Open}"></MenuItem>
                <MenuItem Header="New(_N)" IsChecked="True" x:Name="menuitem01" ></MenuItem>
                <Separator ></Separator>
               
                <MenuItem Header="Save_S"></MenuItem>
            </MenuItem>
            <MenuItem Header="Eidt_E">
                <MenuItem Header="撤销"></MenuItem>
                <Separator>
                    <Separator.Template>
                        <ControlTemplate>
                            <Border Padding="10" BorderThickness="1" BorderBrush="Azure" CornerRadius="3">
                                <TextBlock HorizontalAlignment="Center">分割</TextBlock>
                            </Border>
                        </ControlTemplate>
                    </Separator.Template>
                </Separator>
                <Border Padding="10" BorderThickness="1" BorderBrush="Azure" CornerRadius="3">
                    <TextBlock HorizontalAlignment="Center">分割</TextBlock>
                </Border>
                <MenuItem Header="删除" InputGestureText="Ctr+D"></MenuItem>
            </MenuItem>
        </Menu>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar Band="0" >
                <Button>Line</Button>
                <Button >Rectangle</Button>
            </ToolBar>
            <ToolBar Band="1">
                <Button>Color</Button>
                <Button >Font</Button>
            </ToolBar>
            <ToolBar Band="0" >
                <Button>One</Button>
                <Button >Two</Button>
            </ToolBar>
        </ToolBarTray>
        <StatusBar   DockPanel.Dock="Bottom">
            <!--<StatusBar.ItemTemplate>
                <ItemContainerTemplate>
                    <DockPanel></DockPanel>
                </ItemContainerTemplate>-->
            <!--</StatusBar.ItemTemplate>-->
            <StatusBarItem DockPanel.Dock="Right">账号:</StatusBarItem>
            <StatusBarItem DockPanel.Dock="Top" >状态1</StatusBarItem>
            <StatusBarItem  >状态2</StatusBarItem>
        </StatusBar>
        <ToolBarTray Orientation="Vertical" >
            <ToolBar   >
                <Button  >
                    <Button.Content>
                        <Image Source="/Img/download.png" Width="16" Height="16"></Image>
                    </Button.Content>
                </Button>
                <Button Content="Open"></Button>
                <Button Content="Save"></Button>
                <CheckBox FontWeight="Bold">Bold</CheckBox>
                <CheckBox FontStyle="Italic">Italic</CheckBox>
                <CheckBox >
                    <TextBlock TextDecorations="Underline">UnderLine</TextBlock>
                </CheckBox>
                <ComboBox ToolBar.OverflowMode="Never"  Width="80">

                    <ComboBoxItem>10%</ComboBoxItem>
                    <ComboBoxItem >20%</ComboBoxItem>
                    <ComboBoxItem>30%</ComboBoxItem>


                </ComboBox>
                <Separator></Separator>
            </ToolBar>
        </ToolBarTray>
        
    </DockPanel>
</Window>

1.7,效果:

2,功能区

2.1,使用功能区需要添加程序集System.Windows.Controls.Ribbon。

2.2,引用程序集:

XML 复制代码
 xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"

2.3,为了使快速访问工具栏出现在顶端,需要将默认继承自Window修改为继承自RibbonWindow

cs 复制代码
 public partial class MainWindow : RibbonWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }
    }
XML 复制代码
<r:RibbonWindow x:Class="功能区.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:功能区"
        mc:Ignorable="d"
        xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
       
        Title="MainWindow" Height="350" Width="525">
    <Grid>
      
    </Grid>
</r:RibbonWindow>

2.4,示例:

XML 复制代码
<r:RibbonWindow x:Class="功能区.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:功能区"
        mc:Ignorable="d"
        xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
       
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="279*"/>
        </Grid.RowDefinitions>
        <Ribbon>
<!--定义快速访问工具栏-->
            <Ribbon.QuickAccessToolBar>
                <RibbonQuickAccessToolBar>
                    <RibbonButton Label="Cut" SmallImageSource="/Img/cut.png"></RibbonButton>
                    <RibbonButton Label="Open" SmallImageSource="/Img/open1.png"></RibbonButton>
                </RibbonQuickAccessToolBar>
            </Ribbon.QuickAccessToolBar>
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu SmallImageSource="Img/desktop.png">
                    <RibbonApplicationMenuItem Header="新建" ImageSource="Img/new window.png"></RibbonApplicationMenuItem>
                    <RibbonApplicationMenuItem Header="保存" ImageSource="Img/save.png">
                        <RibbonApplicationMenuItem Header="另存" ImageSource="Img/save-as.png"></RibbonApplicationMenuItem>
                    </RibbonApplicationMenuItem>
                    <RibbonSeparator></RibbonSeparator>
                    <RibbonApplicationMenuItem Header="另存" ImageSource="Img/save-as.png"></RibbonApplicationMenuItem>
                </RibbonApplicationMenu>
            </Ribbon.ApplicationMenu>
            <RibbonTab Header="Home" GroupSizeReductionOrder="ClipBoard,Files">
                <RibbonGroup Header="ClipBoard">
                    <RibbonButton Label="Copy" SmallImageSource="Img/copy.png" LargeImageSource="Img/copy.png"></RibbonButton>
                    <RibbonButton Label="Cut" SmallImageSource="Img/cut.png" LargeImageSource="Img/cut.png"></RibbonButton>
                    <RibbonButton Label="Paste" SmallImageSource="Img/paste.png" LargeImageSource="Img/paste.png" ToolTipTitle="粘贴" ToolTipDescription="对文档进行粘贴等操作" ToolTipImageSource="Img/cut.png" ToolTipFooterTitle="更多信息" ToolTipFooterDescription="按F1获取更多帮助" ToolTipFooterImageSource="Img/help.png"></RibbonButton>
                </RibbonGroup>
                <RibbonGroup Header="ClipBoard">
                    <RibbonButton Label="Copy" SmallImageSource="Img/copy.png" LargeImageSource="Img/copy.png"></RibbonButton>
                    <RibbonButton Label="Cut" SmallImageSource="Img/cut.png" LargeImageSource="Img/cut.png"></RibbonButton>
                    <RibbonButton Label="Paste" SmallImageSource="Img/paste.png" LargeImageSource="Img/paste.png" ToolTipTitle="粘贴" ToolTipDescription="对文档进行粘贴等操作" ToolTipImageSource="Img/cut.png" ToolTipFooterTitle="更多信息" ToolTipFooterDescription="按F1获取更多帮助" ToolTipFooterImageSource="Img/help.png"></RibbonButton>
                </RibbonGroup>
                <RibbonGroup Header="Task">
                    <RibbonButton Label="Copy" SmallImageSource="Img/copy.png" LargeImageSource="Img/copy.png"></RibbonButton>
                    <RibbonButton Label="Cut" SmallImageSource="Img/cut.png" LargeImageSource="Img/cut.png"></RibbonButton>
                    <RibbonButton Label="Paste" SmallImageSource="Img/paste.png" LargeImageSource="Img/paste.png" ToolTipTitle="粘贴" ToolTipDescription="对文档进行粘贴等操作" ToolTipImageSource="Img/cut.png" ToolTipFooterTitle="更多信息" ToolTipFooterDescription="按F1获取更多帮助" ToolTipFooterImageSource="Img/help.png"></RibbonButton>
                </RibbonGroup>
                <RibbonGroup Header="Files">
                    <RibbonButton Label="Copy" SmallImageSource="Img/copy.png" LargeImageSource="Img/copy.png"></RibbonButton>
                    <RibbonButton Label="Cut" SmallImageSource="Img/cut.png" LargeImageSource="Img/cut.png"></RibbonButton>
                    <RibbonButton Label="Paste" SmallImageSource="Img/paste.png" LargeImageSource="Img/paste.png" ToolTipTitle="粘贴" ToolTipDescription="对文档进行粘贴等操作" ToolTipImageSource="Img/cut.png" ToolTipFooterTitle="更多信息" ToolTipFooterDescription="按F1获取更多帮助" ToolTipFooterImageSource="Img/help.png"></RibbonButton>
                </RibbonGroup>
            </RibbonTab>
           
        </Ribbon>
           
      
    </Grid>
</r:RibbonWindow>

注明:

GroupSizeReductionOrder="ClipBoard,Files" ribbonTab中首先被缩小的Group。

快速访问工具栏。Ribbon.QuickAccessToolBar

2.5,效果:

相关推荐
.net开发3 小时前
WPF怎么通过RestSharp向后端发请求
前端·c#·.net·wpf
九鼎科技-Leo3 小时前
WPF 中 NavigationWindow 与 Page 的继承关系解析
wpf
SongYuLong的博客4 小时前
C# WPF 打印机
wpf
就是有点傻4 小时前
WPF中的转换器
wpf
.net开发11 小时前
WPF使用prism框架发布订阅实现消息提示
c#·.net·wpf
那少年已不再......15 小时前
C#WPF使用CommunityToolkit.Mvvm库
开发语言·c#·wpf
SEO-狼术1 天前
Syncfusion Essential Studio WPF 2024 Crack
wpf
Olivia_vivi1 天前
WPF XAML
ui·wpf
就是有点傻1 天前
WPF中如何简单的使用CommunityToolkit.Mvvm创建一个项目并进行 增删改查
wpf
界面开发小八哥1 天前
界面控件DevExpress WPF中文教程:Data Grid——卡片视图概述
.net·wpf·界面控件·devexpress·ui开发