Xaml 将MenuFlyoutPresenter更改为与UWP中的按钮对齐
我正试图让菜单输出对齐按钮的左下角。如果我把按钮放在屏幕的左边,我就可以做到这一点,但是如果按钮在其他任何地方,菜单总是在按钮的正下方居中。我怀疑我必须创建一个模板并更改其中的属性,但我不知道需要更改什么才能实现这一点 我在下面粘贴了我的xaml,并注明了我怀疑需要在哪里进行更改。我是xaml新手,任何帮助或指导都将不胜感激。谢谢Xaml 将MenuFlyoutPresenter更改为与UWP中的按钮对齐,xaml,uwp,windows-10-universal,uwp-xaml,flyout,Xaml,Uwp,Windows 10 Universal,Uwp Xaml,Flyout,我正试图让菜单输出对齐按钮的左下角。如果我把按钮放在屏幕的左边,我就可以做到这一点,但是如果按钮在其他任何地方,菜单总是在按钮的正下方居中。我怀疑我必须创建一个模板并更改其中的属性,但我不知道需要更改什么才能实现这一点 我在下面粘贴了我的xaml,并注明了我怀疑需要在哪里进行更改。我是xaml新手,任何帮助或指导都将不胜感激。谢谢 <Page x:Class="ButtonMenuFlyout.MainPage" xmlns="http://schemas.microsof
<Page
x:Class="ButtonMenuFlyout.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ButtonMenuFlyout"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="BasicTextStyle" TargetType="MenuFlyoutItem">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="13" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Padding" Value="0,0,0,0" />
<Setter Property="MinHeight" Value="36" />
</Style>
<Style x:Key="MenuFlyoutPresenterStyle1" TargetType="MenuFlyoutPresenter">
<Setter Property="Background" Value="#FFFFFF" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Padding" Value="20,0,20,16" />
<Setter Property="Visibility" Value="Visible"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuFlyoutPresenter">
<Grid Background="{TemplateBinding Background}">
<!--[change property in here]-->
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="buttonMenuFlyout"
Content="..."
VerticalAlignment="Top"
HorizontalAlignment="right"
Padding="16,4"
Margin="120,10,0,5"
Background="White">
<Button.Flyout>
<MenuFlyout Opened="MenuFlyout_Opened" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutPresenterStyle1}">
<MenuFlyoutItem Style="{StaticResource BasicTextStyle}" Text="Settings" Click="MenuFlyoutItem_Click" />
<MenuFlyoutItem Style="{StaticResource BasicTextStyle}" Text="Feedback" Click="MenuFlyoutItem_Click_1"/>
<MenuFlyoutItem Style="{StaticResource BasicTextStyle}" Text="Notebook" Click="MenuFlyoutItem_Click_2" />
</MenuFlyout>
</Button.Flyout>
</Button>
</Grid>
</Page>
在您的
菜单中,您可以显式调用ShowAt(UIElement,Point)
方法。
第一个参数可能是您的按钮按钮弹出按钮
;第二个是偏移量,大概是新点(0,ButtonMemoryOut.ActualHeight)
您可以将菜单的位置设置为其父菜单的底部、完整、左侧、右侧或顶部,但在XAML中无法将底部和左侧明确地放在一起。如果设置了弹出式按钮内容,则应了解其实际宽度
以及按钮弹出式按钮
。因此,您可以将Math.Abs((e.NewSize.Width-buttonemumuflyout.Width)/2)的左边距应用于样式内部的网格。在上述情况下,只需向其添加Margin=“78,0,0,0”
`