wpflistviewitemcontainerstyle

Disable ListView selection and hover


Usually I can disable ListView selection doing like this thread suggests - or something similar where you set the ItemContainerStyle.

However I have this ListView that is defined like this:

<ScrollViewer>
    <ListView  ItemsSource="{Binding List, Mode=OneWay}">
        <ListView.View>
            <GridView>
                <GridViewColumn>
                    <GridViewColumnHeader Style="{StaticResource header}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <!-- Some data -->
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridViewColumn>
                ...
            </GridView> 
        </ListView.View>    
    </ListView> 
</ScrollViewer> 

And if I try to specify the ItemContainerStyle - the data in the list just disappears.

Giving the above ListView, how would I proceed just to removed the selection?


Solution

  • Can you try this ItemContainerStyle? This basically will not pick up any input events.

    <ListView ItemsSource="{Binding List, Mode=OneWay}">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListViewItem}}">
                <Setter Property="IsHitTestVisible" Value="False"/>
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>