Listview und weißer bereich an den Rändern



  • Hallo

    In meinem WPF Projekt habe ich eine ListView. In der Listview stelle ich über ein DataTemplate mehrere Buttons dar. Was mich nun stört ist der Rand im Listview. Ich möchte das die Buttons ohne Abstand am linken oberen Rand beginnen.

    Padding = 0 des Listview hat leider nichts gebracht. Margin der Buttons ist auch auf 0. Was muss man da noch setzen?



  • Hi,

    nur aus dem Bauch heraus: Probier mal ein negatives Padding bzw. Margin zu setzen.



  • Habe ich auch schon. Muss dann aber auch unregelmässig sein.
    Fand ich nicht ganz so schön und dachte es gibt eine bessere Lösung.



  • Dann kommst du wohl nicht um einen eigenen Stil für das ListViewItem herum:

    <Style x:Key="{x:Type ListViewItem}" TargetType="{x:Type ListViewItem}" xmlns:s="clr-namespace:System;assembly=mscorlib">
                <Style.Resources>
                    <ResourceDictionary />
                </Style.Resources>
                <Setter Property="Panel.Background">
                    <Setter.Value>
                        <SolidColorBrush>
                            #00FFFFFF</SolidColorBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.HorizontalContentAlignment">
                    <Setter.Value>
                        <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.VerticalContentAlignment">
                    <Setter.Value>
                        <Binding Path="VerticalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.Padding">
                    <Setter.Value>
                        <Thickness>
                            0,0,0,0</Thickness>
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" Name="Bd" SnapsToDevicePixels="True">
                                <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Selector.IsSelected">
                                    <Setter Property="Panel.Background" TargetName="Bd">
                                        <Setter.Value>
                                            <DynamicResource ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="TextElement.Foreground">
                                        <Setter.Value>
                                            <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
                                        </Setter.Value>
                                    </Setter>
                                    <Trigger.Value>
                                        <s:Boolean>
                                            True</s:Boolean>
                                    </Trigger.Value>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="Selector.IsSelected">
                                            <Condition.Value>
                                                <s:Boolean>
                                                    True</s:Boolean>
                                            </Condition.Value>
                                        </Condition>
                                        <Condition Property="Selector.IsSelectionActive">
                                            <Condition.Value>
                                                <s:Boolean>
                                                    False</s:Boolean>
                                            </Condition.Value>
                                        </Condition>
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Panel.Background" TargetName="Bd">
                                        <Setter.Value>
                                            <DynamicResource ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="TextElement.Foreground">
                                        <Setter.Value>
                                            <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
                                        </Setter.Value>
                                    </Setter>
                                </MultiTrigger>
                                <Trigger Property="UIElement.IsEnabled">
                                    <Setter Property="TextElement.Foreground">
                                        <Setter.Value>
                                            <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                        </Setter.Value>
                                    </Setter>
                                    <Trigger.Value>
                                        <s:Boolean>
                                            False</s:Boolean>
                                    </Trigger.Value>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    

    Das Padding steht im Standardstil auf 2,0,0,0


Anmelden zum Antworten