如何消除C# UWP中按钮与其Flyout之间的间距?
嘿,我来帮你搞定这个问题!要让Button和它的Flyout之间完全没有边距,咱们只需要调整MenuFlyout的展示容器样式,抵消掉系统默认的间距就行。直接修改你的代码如下:
<Grid> <Button Height="100" Width="100" Content="More" Name="MoreButton"> <Button.Flyout> <MenuFlyout x:Name="MoreButtonFlyout" Placement="Bottom"> <MenuFlyout.FlyoutPresenterStyle> <Style TargetType="FlyoutPresenter"> <!-- 移除Flyout容器的默认边距和内边距 --> <Setter Property="Margin" Value="0"/> <Setter Property="Padding" Value="0"/> </Style> </MenuFlyout.FlyoutPresenterStyle> <MenuFlyoutItem x:Name="ReplayOn" FontSize="12" FontFamily="Segoe UI Regular" HorizontalAlignment="Left" Foreground="#252525" Text="Item 1" Height="32"/> </MenuFlyout> </Button.Flyout> </Button> </Grid>
关键细节说明:
- 系统默认的
FlyoutPresenter(承载Flyout内容的容器)自带了细微的边距,通过自定义FlyoutPresenterStyle并将Margin和Padding设为0,就能彻底消除Button与Flyout之间的间隙。 - 如果调整后仍有极窄的缝隙,可以尝试将
Margin设为-1,以此抵消系统层面的最小布局间距。
这样修改后,你的Flyout就会完全紧贴Button底部显示啦!
内容的提问来源于stack exchange,提问作者Mushfiqur Rahman
相关产品推荐
相关产品推荐

