ItemsControl项目之间有空格

时间:2014-10-25 12:15:16

标签: c# wpf wpf-controls itemscontrol

我的物品之间有空间,我无法移除它。我整天都在谷歌搜索ItemsControl,发现什么都行不通。它也没有与listbox一起使用。它甚至使情况变得更糟。

有人有想法吗?

这是我的代码:

                <ItemsControl BorderThickness="0" ItemsSource="{Binding Items}" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter Property="FrameworkElement.Margin" Value="0,0,0,0"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="{x:Type newsSubscriber:Item}">
                        <Border VerticalAlignment="Stretch" SnapsToDevicePixels="True" BorderThickness="0">
                            <Border.Background>
                                <ImageBrush Stretch="Fill" ImageSource="{Binding RepeatImagePath}"/>
                            </Border.Background>
                            <StackPanel Cursor="Hand" VerticalAlignment="Stretch">
                                <StackPanel.InputBindings>
                                    <MouseBinding MouseAction="LeftClick" Gesture="LeftClick" Command="{Binding GoToWebCommand}" />
                                </StackPanel.InputBindings>
                                <StackPanel VerticalAlignment="Stretch" FlowDirection="RightToLeft" Height="{Binding hight}" Orientation="Horizontal"  HorizontalAlignment="Right">
                                    <StackPanel.Background>
                                        <ImageBrush Stretch="Fill" ImageSource="{Binding RepeatImagePath}"/>
                                    </StackPanel.Background>
                                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" Width="70" Text="{Binding time}"/>
                                    <TextBlock Language="he-il" TextWrapping="Wrap" HorizontalAlignment="Right" VerticalAlignment="Center" Width="300" Text="{Binding title}"/>
                                    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="38">
                                        <Image Stretch="None" Source="{Binding ArrowImagePath}"/>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

输出图片: output

2 个答案:

答案 0 :(得分:0)

你可能有高度=&#34; {Binding hight}&#34;属性设置为一些大的值。

<StackPanel VerticalAlignment="Stretch" 
            FlowDirection="RightToLeft" 
            Height="{Binding hight}" 
            Orientation="Horizontal"  
            HorizontalAlignment="Right">

答案 1 :(得分:0)

你在FrameworkElement.Margin的正确轨道上设置Value =&#34; -1&#34;。它会创建一个小的重叠,从而消除空间。

<Setter Property="FrameworkElement.Margin" Value="-1"/>