【发布时间】:2019-02-27 09:12:30
【问题描述】:
我在我的 UWP 应用中使用 Flyout 元素:
<Flyout Placement="Full"/>
这会根据需要打开应用中心的弹出窗口。但我无法更改弹出窗口的高度和宽度。如何才能做到这一点?
【问题讨论】:
我在我的 UWP 应用中使用 Flyout 元素:
<Flyout Placement="Full"/>
这会根据需要打开应用中心的弹出窗口。但我无法更改弹出窗口的高度和宽度。如何才能做到这一点?
【问题讨论】:
XAML 等同于接受的答案。
(注意:OP 发布了 Flyout - 而不是 MenuFlyout):
<Flyout>
...
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="MinWidth" Value="200" />
<Setter Property="MinHeight" Value="200" />
</Style>
</Flyout.FlyoutPresenterStyle>
...
</Flyout>
【讨论】:
类似下面的代码应该可以满足您的需要。
private void Flyout_Opened(object sender, object e)
{
Flyout f = sender as Flyout;
Style s = new Windows.UI.Xaml.Style { TargetType = typeof(FlyoutPresenter) };
s.Setters.Add(new Setter(MinHeightProperty, "200"));
s.Setters.Add(new Setter(MinWidthProperty, "200"));
f.FlyoutPresenterStyle = s;
}
【讨论】:
我想补充一点,即使您调整弹出窗口的大小,内容也会被放置在水平滚动查看器中。这意味着,如果你在里面放一个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 的属性。
【讨论】: