首页 > 代码库 > D25_01_菜单(menu ContextMenu)
D25_01_菜单(menu ContextMenu)
<Window x:Class="demo.MixedMenus" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MixedMenus" Height="350" Width="525"> <Grid Margin="5"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <StackPanel> <!--Menu菜单--> <Menu VerticalAlignment="Top" IsMainMenu="True"> <MenuItem Header="File"> <MenuItem Header="Open"></MenuItem> </MenuItem> </Menu> <Button Padding="3" Margin="5">An Ordinary Button</Button> </StackPanel> <TextBox Grid.Row="1" Margin="5" Name="txt1"> <TextBox.Text>A TextBox</TextBox.Text> <!--ContextMenu菜单--> <TextBox.ContextMenu> <ContextMenu> <!--ClearText事件处理方法--> <MenuItem Header="ClearText" Click="ClearText"></MenuItem> <MenuItem Header="Close"></MenuItem> </ContextMenu> </TextBox.ContextMenu> </TextBox> <StackPanel Grid.Row="1" Grid.Column="1"> <CheckBox Margin="5">A CheckBox</CheckBox> <Menu VerticalAlignment="Top"> <MenuItem Header="File"></MenuItem> <MenuItem Header="Help"></MenuItem> </Menu> </StackPanel> <Menu Grid.Row="3" Margin="5" VerticalAlignment="top" HorizontalAlignment="Left"> <MenuItem Header="File"> <!--IsCheckable:点过后通过对号记录是否点击过--> <MenuItem Header="New" IsCheckable="True"></MenuItem> <MenuItem Header="Open" Click="MenuItem_Click" IsCheckable="True"></MenuItem> <MenuItem Header="Save"></MenuItem> </MenuItem> </Menu> </Grid></Window>
<Window x:Class="demo.SideBarMenu" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="SideBarMenu" Height="326.4" Width="456.8"> <DockPanel LastChildFill="True" Margin="5"> <Border BorderBrush="SteelBlue" BorderThickness="1"> <ScrollViewer DockPanel.Dock="Left"> <Menu> <Menu.ItemsPanel> <ItemsPanelTemplate> <StackPanel Background="White"></StackPanel> </ItemsPanelTemplate> </Menu.ItemsPanel> <MenuItem Header="File"> <MenuItem Header="New"></MenuItem> <MenuItem Header="Open"></MenuItem> <MenuItem Header="Save"></MenuItem> </MenuItem> <MenuItem Header="Help"></MenuItem> </Menu> </ScrollViewer> </Border> <TextBox Margin="5,0,0,0" TextWrapping="Wrap">Other content goes here.</TextBox> </DockPanel></Window>
<Window x:Class="demo.MenuWithSubHeading" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MenuWithSubHeading" Height="300" Width="300"> <Grid> <Grid.RowDefinitions > <RowDefinition Height="Auto"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Menu> <MenuItem Header="File"> <MenuItem Header="New"></MenuItem> <MenuItem Header="Open"></MenuItem> <MenuItem Header="Save"></MenuItem> <Separator></Separator> <MenuItem Header="Exit"></MenuItem> </MenuItem> <MenuItem Header="Edit"> <MenuItem Header="Undo"></MenuItem> <MenuItem Header="Redo"></MenuItem> <Separator> <Separator.Template> <ControlTemplate> <Border CornerRadius="2" Padding="5" BorderBrush="Black" BorderThickness="1" Background="PaleGoldenrod"> <TextBlock FontWeight="Bold"> Editing Commands </TextBlock> </Border> </ControlTemplate> </Separator.Template> </Separator> <MenuItem Header="Cut"></MenuItem> <MenuItem Header="Copy"></MenuItem> <MenuItem Header="Paste"></MenuItem> </MenuItem> </Menu> </Grid></Window>
D25_01_菜单(menu ContextMenu)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。