我在UWP应用中使用的Flyout元素为:
<Flyout Placement="Full"/>
这将根据需要在应用程序的中心打开弹出窗口。但是我无法更改弹出窗口的高度和宽度。如何才能做到这一点?
答案 0 :(得分:1)
类似下面的代码应该可以满足您的需求。
private void MenuFlyout_Opened(object sender, object e)
{
MenuFlyout f = sender as MenuFlyout;
Style s = new Windows.UI.Xaml.Style { TargetType = typeof(MenuFlyoutPresenter) };
s.Setters.Add(new Setter(MinHeightProperty, "200"));
s.Setters.Add(new Setter(MinWidthProperty, "200"));
f.MenuFlyoutPresenterStyle = s;
}
答案 1 :(得分:1)
XAML等同于接受的答案。
(注意:OP发布了弹出窗口-而不是MenuFlyout):
<Flyout>
...
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="MinWidth" Value="200" />
<Setter Property="MinHeight" Value="200" />
</Style>
</Flyout.FlyoutPresenterStyle>
...
</Flyout>
答案 2 :(得分:0)
我想补充一点,即使您调整浮出控件的大小,内容也会放置在水平滚动查看器中。这意味着,如果您在里面放置一个 TextBox
,它将根据其内容无限放大。问题是also described on microsoft forums。
为了修复,您可以添加:
<Flyout.FlyoutPresenterStyle>
<!--Disable infinite flyout width-->
<Style TargetType="FlyoutPresenter">
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
</Style>
</Flyout.FlyoutPresenterStyle>
这不适用于直接设置为 Flyout for some reason 的属性。