Xaml UWP中的按钮菜单弹出式水平对齐

Xaml UWP中的按钮菜单弹出式水平对齐,xaml,uwp,Xaml,Uwp,我需要将菜单设置为右对齐。我使用了代码,但它只显示在左侧。我需要在样式中进行修改吗 <Button Content="Click" HorizontalAlignment="Right" Height="30" Width="30"> <Button.Flyout> <MenuFlyout Placement="Bottom"> <MenuFlyout.MenuFlyoutPrese

我需要将菜单设置为右对齐。我使用了代码,但它只显示在左侧。我需要在样式中进行修改吗

<Button Content="Click" HorizontalAlignment="Right" Height="30" Width="30">
        <Button.Flyout>
            <MenuFlyout Placement="Bottom">
                <MenuFlyout.MenuFlyoutPresenterStyle>
                    <Style TargetType="MenuFlyoutPresenter">
                        <Setter Property="HorizontalAlignment" Value="Right" />
                        <Setter Property="MaxWidth" Value="50" />
                        <Setter Property="MaxHeight" Value="50" />
                    </Style>
                </MenuFlyout.MenuFlyoutPresenterStyle>
                <MenuFlyoutItem Text="Item" />
            </MenuFlyout>
        </Button.Flyout>
    </Button>


实际上,如果您使用默认设置并设置
MenuFlyout
Placement
属性,位置看起来应该很好。当我修改你的代码时,它应该可以按照你的需要正常工作。你可以从截图中查看

<Button Content="Click" HorizontalAlignment="Right" Height="30" Width="114" Margin="0,200,0,0" VerticalAlignment="Top" >
    <Button.Flyout>
        <MenuFlyout Placement="Bottom">
            <MenuFlyoutItem Text="Item" HorizontalAlignment="Right" />
        </MenuFlyout>
    </Button.Flyout>
</Button>


实际上,如果您使用默认设置并设置
MenuFlyout
Placement
属性,位置看起来应该很好。当我修改你的代码时,它应该可以按照你的需要正常工作。你可以从截图中查看

<Button Content="Click" HorizontalAlignment="Right" Height="30" Width="114" Margin="0,200,0,0" VerticalAlignment="Top" >
    <Button.Flyout>
        <MenuFlyout Placement="Bottom">
            <MenuFlyoutItem Text="Item" HorizontalAlignment="Right" />
        </MenuFlyout>
    </Button.Flyout>
</Button>


从屏幕截图上看,您似乎正在开发Windows Phone 8.1应用程序,而不是UWP应用程序

使用UWP时,您的代码(我在
按钮中删除
高度
宽度
)如下所示:

我想这就是你想要的

但在WindowsPhone8.1中,我们必须修改
MenuFlyoutPresenter
的模板才能实现这一点

要修改
菜单输出演示者的模板
,我们可以在“文档大纲”中选择“[MenuFlyout]”并右键单击,然后选择“编辑其他模板”→ “编辑菜单OutPresenterStyle”→ “编辑副本…

在模板中,我们需要将
外边框
中心边框
内边框
水平对齐
设置为
右侧

<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
    ...
    <Border x:Name="CenterBorder" BorderBrush="{TemplateBinding Background}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
        <StackPanel x:Name="InnerBorder" Background="{TemplateBinding Background}" FlowDirection="{TemplateBinding FlowDirection}" HorizontalAlignment="Right">
        ...
        </StackPanel>
    </Border>
</Border>
它看起来像:


您还可以在
菜单的
样式中更改其他属性以美化它。

从屏幕截图上看,您似乎正在开发Windows Phone 8.1应用程序,而不是UWP应用程序

使用UWP时,您的代码(我在
按钮中删除
高度
宽度
)如下所示:

我想这就是你想要的

但在WindowsPhone8.1中,我们必须修改
MenuFlyoutPresenter
的模板才能实现这一点

要修改
菜单输出演示者的模板
,我们可以在“文档大纲”中选择“[MenuFlyout]”并右键单击,然后选择“编辑其他模板”→ “编辑菜单OutPresenterStyle”→ “编辑副本…

在模板中,我们需要将
外边框
中心边框
内边框
水平对齐
设置为
右侧

<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
    ...
    <Border x:Name="CenterBorder" BorderBrush="{TemplateBinding Background}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
        <StackPanel x:Name="InnerBorder" Background="{TemplateBinding Background}" FlowDirection="{TemplateBinding FlowDirection}" HorizontalAlignment="Right">
        ...
        </StackPanel>
    </Border>
</Border>
它看起来像:

您还可以在
菜单的
样式中更改其他属性,以美化它