0

I have a wpf application where I use a listView with a gridView set as its view. It has several columns which I've customized.
The problem is they don't fill the entire listView width, as in the image below: enter image description here

Below are the styles for listview and gridview column header:

<!-- 
    GridView column header
    -->
    <Style TargetType="{x:Type GridViewColumnHeader}" x:Key="style_header">
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="Foreground" Value="#90969e"/>
            <Setter Property="FontWeight" Value="Light"/>
            <Setter Property="Height" Value="24"/>
            <Setter Property="IsHitTestVisible" Value="False"/>
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="Background">            
                <Setter.Value>
                    <ImageBrush ImageSource="/images/bg_title_table_strip.png"/>
                </Setter.Value>
            </Setter>        
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <ImageBrush ImageSource="/images/black_line.png"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                        <Grid SnapsToDevicePixels="true">
                            <Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0, 1" Background="{TemplateBinding Background}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition MaxHeight="7"/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Rectangle x:Name="UpperHighlight" Fill="Transparent" Visibility="Collapsed"/>
                                    <Border Padding="{TemplateBinding Padding}" Grid.RowSpan="2">
                                        <ContentPresenter x:Name="HeaderContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    </Border>
                                </Grid>
                            </Border>
                            <Canvas>
                                <Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
                            </Canvas>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="{x:Null}"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="{x:Null}"/>
                            </Trigger>
                            <Trigger Property="Height" Value="Auto">
                                <Setter Property="MinHeight" Value="20"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    <!-- 
        ListView
        -->
        <Style x:Key="style_listView"  TargetType="{x:Type ListView}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="MinWidth" Value="1072"/>
            <Setter Property="Height" Value="686"/>
            <Setter Property="AlternationCount" Value="2"/>
            <Setter Property="Margin" Value="10,10,11,14"/>
            <!--<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>-->
        </Style>

Q:  What is wrong and how can it be solved?
Any help highly appreciated.

Mike Spike
  • 389
  • 8
  • 20
  • *What is wrong and how can it be solved?*... nothing is wrong. Your content just doesn't naturally fill the space. If however, you are *actually* asking how to fill the space of the `GridView` with your columns, you could try to set the `HorizontalContentAlignment` property of the `ListView` to `Stretch`. – Sheridan Jul 25 '14 at 15:46
  • Yes, how to fill the space of the GridView is exactly what I want to know. I tried to set that property to Stretch, but it has no changes on the UI. – Mike Spike Jul 25 '14 at 17:58
  • Then there is no simple property setting that you can use to do that. If the solution to the duplicate question doesn't help, you can also look at the answer to the [WPF : Extend last column of ListView's GridView](http://stackoverflow.com/questions/911243/wpf-extend-last-column-of-listviews-gridview) question too. – Sheridan Jul 25 '14 at 18:20

0 Answers0