我无法弄清楚这个错误,所以我将其剥离为最简单的版本,但它仍然会发生。
这是我的 XAML 代码:
<Grid>
<Button x:Name="button1" Content="Button" VerticalAlignment="Top">
<Button.Flyout>
<Flyout Placement="Right">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</Flyout.FlyoutPresenterStyle>
<Grid Name="PopupGrid" Background="Aqua"/>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
然后我有一个针对该页面的事件:
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
PopupGrid.Height = Window.Current.Bounds.Height;
}
因此该代码的预期行为如下:按下按钮后,将打开一个弹出窗口,该弹出窗口在窗口中垂直拉伸(stretch)。这一切都完美无缺,直到我把 window 弄得太高为止。 Here's我所描述内容的 GIF。
正如你所看到的,弹出窗口显然认为它应该是窗口的高度,但由于某种原因它只是在某个时刻停止扩展,并添加了一个滚动条。
我在这里没有看到什么吗?或者这些弹出窗口是否有一些我从未听说过的任意最大高度?
最佳答案
弹出窗口确实有最大高度限制。在 FlyoutPresenter styles and templates ,你可以找到FlyoutPresenter将 MaxHeight
属性设置为 FlyoutThemeMaxHeight
:
<Setter Property="MinWidth" Value="{ThemeResource FlyoutThemeMinWidth}"/>
<Setter Property="MaxWidth" Value="{ThemeResource FlyoutThemeMaxWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource FlyoutThemeMinHeight}"/>
<Setter Property="MaxHeight" Value="{ThemeResource FlyoutThemeMaxHeight}"/>
而FlyoutThemeMaxHeight
是一个主题资源,代表758
:
<x:Double x:Key="FlyoutThemeMaxHeight">758</x:Double>
您可以尝试将FlyoutPresenter
的MaxHeight
重置为PositiveInfinity (可以在 XAML 中将其设置为简单的“Infinity”),如下所示,网格应该能够在窗口上垂直拉伸(stretch)。
<Button x:Name="button1" VerticalAlignment="Top" Content="Button">
<Button.Flyout>
<Flyout Placement="Right">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="MaxHeight" Value="Infinity" />
</Style>
</Flyout.FlyoutPresenterStyle>
<Grid Name="PopupGrid" Background="Aqua" />
</Flyout>
</Button.Flyout>
</Button>
关于c# - UWP - 按钮弹出按钮以某种方式锁定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41310600/