Resolved Items in listview not populating with template

Tewl

Member
Joined
Jan 13, 2022
Messages
8
Programming Experience
5-10
I have a simple listview with one column in a gridview for displaying a list of names, (Using a listview instead of a listbox because more columns will be added later) The listview are dispayed on multiple windows so I have a separate resourcedictionary file defining the style of the listview. My issue starts when trying to edit the border of the listview the items do not populate the list.

Listview Xaml:
            <ListView Grid.Column="1"
                      Width="130"
                      ItemsSource="{Binding Users}">
                <ListView.View>
                    <GridView>
                        <GridView.ColumnHeaderContainerStyle>
                            <Style>
                                <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>                              
                            </Style>
                        </GridView.ColumnHeaderContainerStyle>
                        <GridViewColumn Header="Names" Width="130" DisplayMemberBinding="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
                    </GridView>
                </ListView.View>
            </ListView>

ListviewTheme.xaml:
    <Style x:Key="{x:Type ListView}" TargetType="{x:Type ListView}">
        <Setter Property="Background" Value="#2F3136"/>
        <Setter Property="BorderBrush" Value="#FFABAdB3"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Margin" Value="1,1,1,3" />
        <Setter Property="Padding" Value="0,2,0,2"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible"/>
        <!-- If I add the code below the list will not show -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListView}">
                    <!-- If I set a background in the border I see an outline of the listview but no items will be added -->
                    <Border CornerRadius="3"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Still new to WPF, thanks for any help.
 
Solution
With plain old styles and specific properties, the setters just override the existing values for those properties that already exist on the control. So it looks like what you are doing is just additive or decorations on an existing control. What is special about the "Template" property is that it is the blueprints for the control. You can't do "additive" changes to it. You need to replace the entire template. You can't just overwrite part of the existing template.

More readings here:
With plain old styles and specific properties, the setters just override the existing values for those properties that already exist on the control. So it looks like what you are doing is just additive or decorations on an existing control. What is special about the "Template" property is that it is the blueprints for the control. You can't do "additive" changes to it. You need to replace the entire template. You can't just overwrite part of the existing template.

More readings here:
 
Solution
Back
Top Bottom