首页 > 代码库 > D25_01_菜单(menu ContextMenu)

D25_01_菜单(menu ContextMenu)

image

 

<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>

 

imageimage

<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>

 

imageimage

 

<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)