在弹出窗口内删除ListViewItem上的填充

时间:2016-05-24 14:39:23

标签: 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但是它总是在项目的两侧之间有一个空格弹出的边缘。

2 个答案:

答案 0 :(得分:1)

因为我在评论中因为我的许多快速回答的坏习惯而被戳了戳......

查看FlyoutPresenter <Thickness x:Key="FlyoutContentThemePadding">12,11,12,12</Thickness>的结构,我们注意到有一个填充绑定到的资源;

{{1}}

当你注意到你的Flyout内容有点挤压时,这通常是罪魁祸首。虽然是ListView和其他ItemsControl变体通常有自己的模板Paddings / Margins可以干扰,我们越多地将某些内容嵌入到其他模板化控件中,就越需要排序以找到我们的罪魁祸首。

很高兴它有所帮助。 :)

答案 1 :(得分:0)

尝试在ItemContainerStyle中覆盖边距和填充:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Margin" Value="0"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="MinWidth" Value="0"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

可能需要MinWidth和MinHeight来设置0。