xaml - 删除弹出控件内 ListViewItem 上的填充

标签 xaml listview windows-runtime windows-store

当我按下按钮时,我会显示以下弹出窗口

<Flyout x:Name="saveDiscardMenu" Placement="Bottom" >
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <ListView Name="SaveDiscardList" ItemClick="SaveDiscardList_ItemClick" >
                <ListViewItem Style="{StaticResource ListViewItemPDF}">
                    <TextBlock x:Uid="SaveChanges" Name="saveChanges"  Grid.Row="0" Tapped="saveChanges_Tapped"></TextBlock>
                </ListViewItem>
                <ListViewItem Style="{StaticResource ListViewItemPDF}">
                    <TextBlock x:Uid="DiscardChanges" Name="discardChanges" Grid.Row="1" Margin="0,20,0,0" Tapped="discardChanges_Tapped" ></TextBlock>
                </ListViewItem>
            </ListView>
        </Grid>
    </Flyout>

看起来像这样enter image description here

我用它作为我的 ListViewItem 样式

<Style TargetType="ListViewItem" x:Key="ListViewItemPDF">
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="TabNavigation" Value="Local"/>
    <Setter Property="IsHoldingEnabled" Value="True"/>
    <Setter Property="Margin" Value="0,0,0,0"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListViewItem">
                <ListViewItemPresenter
                ContentTransitions="{TemplateBinding ContentTransitions}"
                Padding="{TemplateBinding Padding}"
                SelectionCheckMarkVisualEnabled="True"
                CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}"
                CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}"
                CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}"
                DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
                DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
                FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}"
                PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
                PointerOverBackground="{StaticResource MyLightBlue}"
                SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}"
                SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}"
                SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}"
                SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}"
                SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}"
                DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
                DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
                ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                PointerOverBackgroundMargin="1"
                ContentMargin="4" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我想知道的是如何删除每个项目似乎具有的左右填充,我尝试将边距和填充设置为 0,但项目两侧之间似乎总是有一个空格,弹出按钮的边缘。

最佳答案

因为我刚刚因为在评论中快速回答的坏习惯而受到批评......

查看 default control style template 的结构对于 FlyoutPresenter我们注意到有一个填充绑定(bind)到一个资源;

<Thickness x:Key="FlyoutContentThemePadding">12,11,12,12</Thickness>

当您发现弹出内容有点被压扁时,这通常是罪魁祸首。是的,ListView 和其他 ItemsControl 变体通常都有自己的模板化 Paddings/Margins,它们可能会产生干扰,但我们在其他模板化控件中嵌入的内容越多,需要排序以找到罪魁祸首的层就越多。

很高兴有帮助。 :)

关于xaml - 删除弹出控件内 ListViewItem 上的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37416776/

相关文章:

android - 如何针对新的 Android 准则对单个列表项采取行动?

xaml - 如何解决 Metro 风格应用程序中 XAML 中 webview 控件的 z-index 问题?

windows - 获取线程信息/环境 block (TIB/TEB)的官方方式

c++ - 错误 C2664 'HRESULT IUnknown::QueryInterface(const IID &,void **)' : cannot convert argument 1 from 'const winrt::guid' to 'const IID &'

c# - 单击 Xamarin Forms 中的提交按钮后如何从 XAML 获取值?

wpf - 如何在 Windows 8 商店应用程序中访问 Parent 的 DataContext

wpf - 当 Popup 的 IsOpen 属性设置为 True 时开始 StoryBoard

android - 使用 ArrayAdapter 在 listView 中添加标题

ListView中的Android数据

c# - 从 UWP XAML 中的 HyperlinkBut​​ton 中删除下划线