[英]Change height and width of Flyout in UWP app
我在我的 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
,它將根據其內容無限放大。 微軟論壇上也描述了這個問題。
為了修復,您可以添加:
<Flyout.FlyoutPresenterStyle>
<!--Disable infinite flyout width-->
<Style TargetType="FlyoutPresenter">
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
</Style>
</Flyout.FlyoutPresenterStyle>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.