获取UWP上菜单栏的实际宽度和高度
有没有办法在UWP中获得MenyFlyout的实际宽度和高度 例如,我发现您可以这样设置获取UWP上菜单栏的实际宽度和高度,uwp,Uwp,有没有办法在UWP中获得MenyFlyout的实际宽度和高度 例如,我发现您可以这样设置MinWidth(顺便说一句,非常有用): MenuFlyout m = this as MenuFlyout; Style s = new Windows.UI.Xaml.Style { TargetType = typeof(MenuFlyoutPresenter) }; s.Setters.Add(new Setter(MenuFlyoutPresenter.MinWidthProperty, _
MinWidth
(顺便说一句,非常有用):
MenuFlyout m = this as MenuFlyout;
Style s = new Windows.UI.Xaml.Style { TargetType = typeof(MenuFlyoutPresenter) };
s.Setters.Add(new Setter(MenuFlyoutPresenter.MinWidthProperty, _minWidth + ""));
m.MenuFlyoutPresenterStyle = s;
我只是找不到一种简单的方法来查询宽度和高度。似乎我们无法在UWP中获得MenyFlyout的实际宽度和高度 您通常不会在XAML或代码中直接使用MenuFlyoutPresenter。相反,可以引用MenuFlyoutPresenter类型作为MenuFlyout.MenuFlyoutPresenterStyle属性所用样式的TargetType 有关详细信息,请参阅 无法使用MenuFlyoutPresenter.ActualWidth属性获取实际宽度
MenuFlyout
的实际宽度取决于MenuFlyout演示器的MinWidth
、MaxWidth
和MenuFlyout
的内容宽度
如果您想获得与页面相适应的实际宽度和高度,您应该能够设置MenuFlyoutPresenter
的MinWidth
和MaxWidth
。无论内容的宽度如何变化,MenuFlyout
对于您的页面来说都不能太大或太小
例如:
<MenuFlyout x:Name="MyMenuFlyout" >
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="MaxWidth" Value="500"/>
<Setter Property="MinWidth" Value="50"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
</MenuFlyout>
您应该在弹出按钮的内容控件中定义高度和宽度。我从未使用过弹出按钮,但应该有办法获取其框架元素并订阅SizeChanged事件,该事件在更改ActualWidth或ActualHeight时触发。