2

这是代码:

<Style TargetType="{x:Type MenuItem}">


    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type MenuItem}">

                <Border Name="Border" >
                    <Grid>
                        <ContentPresenter Margin="6,3,10,3" ContentSource="Header" RecognizesAccessKey="True" />
                        <Popup  Width="auto" AllowsTransparency="True" Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" Focusable="False" PopupAnimation="Fade">
                            <Border Opacity="1" Name="SubmenuBorder" SnapsToDevicePixels="True" >
                                <Border.Background>
                                    <SolidColorBrush Color="#FF9FD3F3"/>
                                </Border.Background>
                                <StackPanel  IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                <Border.BorderBrush>
                                    <SolidColorBrush Color="Pink"></SolidColorBrush>
                                </Border.BorderBrush>
                                <Border.BorderThickness>
                                    <Thickness Bottom="3" Top="3" Left="3" Right="3" ></Thickness>
                                </Border.BorderThickness>
                            </Border>
                        </Popup>
                    </Grid>

                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                        <Setter TargetName="Popup" Property="PopupAnimation" Value="Fade"/>
                    </Trigger>

                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Effect" Value="{StaticResource dropShadow}"/>
                        <Setter TargetName="Border" Property="Background" Value="#f9cef9"/>

                    </Trigger>                      


                    **<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                        <Setter TargetName="SubmenuBorder" Property="Padding" Value="10,0,0,3"/>
                    </Trigger>**




                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>


</Style>

如何将方向放在右侧?这是一个水平菜单,当我单击子菜单下拉菜单时,没错,但是我有一个带有子菜单的子项,我希望它们以正确的方向而不是下拉菜单打开

4

1 回答 1

0

Popup Placement 设置为“Bottom”,在 WpfToolkit SplitButton 上的以下代码中将其更改为“Right”:

要包含该工具包,请在顶部添加以下行:

xmlns:wpfTools="http://schemas.xceed.com/wpf/xaml/toolkit"

然后..

            <wpfTools:SplitButton Command="local:MainWindow.***" ToolTip="Resolutions">
                <wpfTools:SplitButton.DropDownContent>
                    <Menu x:Name="***">
                        <Menu.Resources>

                            <Style TargetType="{x:Type MenuItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type MenuItem}">
                                            <Border Name="Border" >
                                                <Grid>
                                                    <ContentPresenter Margin="6,3,10,3" ContentSource="Header" RecognizesAccessKey="True" />
                                                    <Popup  Width="auto" AllowsTransparency="True" Name="Popup" Placement="Right" IsOpen="{TemplateBinding IsSubmenuOpen}" Focusable="False" PopupAnimation="Fade">
                                                        <Border Opacity="1" Name="SubmenuBorder" SnapsToDevicePixels="True" >
                                                            <Border.Background>
                                                                <SolidColorBrush Color="#FF9FD3F3"/>
                                                            </Border.Background>
                                                            <StackPanel  IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                                            <Border.BorderBrush>
                                                                <SolidColorBrush Color="Pink"></SolidColorBrush>
                                                            </Border.BorderBrush>
                                                            <Border.BorderThickness>
                                                                <Thickness Bottom="3" Top="3" Left="3" Right="3" ></Thickness>
                                                            </Border.BorderThickness>
                                                        </Border>
                                                    </Popup>
                                                </Grid>
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                                                    <Setter TargetName="Popup" Property="PopupAnimation" Value="Fade"/>
                                                </Trigger>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <!--
                                                    <Setter Property="Effect" Value="{StaticResource dropShadow}"/>
                                                    -->
                                                    <Setter TargetName="Border" Property="Background" Value="#f9cef9"/>
                                                </Trigger>
                                                <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                                                    <Setter TargetName="SubmenuBorder" Property="Padding" Value="10,0,0,3"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Menu.Resources>

                        <Menu.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </Menu.ItemsPanel>
                        <MenuItem Header="Test1">

                            <MenuItem Header="test 1" />
                            <MenuItem Header="test 2" />
                            <MenuItem Header="test 3" />
                        </MenuItem>
                        <MenuItem Header="Test2">
                            <MenuItem Header="test 1" />
                            <MenuItem Header="test 2" />
                            <MenuItem Header="test 3" />
                        </MenuItem>
                    </Menu>

                </wpfTools:SplitButton.DropDownContent>
                <Image Width="32" Source="***.ico" />
            </wpfTools:SplitButton>

编码:

                        <Menu.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </Menu.ItemsPanel>

使第一个 MenuItem 垂直放置,而不是默认水平放置。

于 2014-01-01T04:51:22.313 回答