Microsoft Developer Network >
Página principal de foros
>
Windows Presentation Foundation (WPF)
>
Disable ListView selection and hover cues
Disable ListView selection and hover cues
- I'm developing a ListView with a GridView in it. I am coloring each ListViewItem based on a magnitude figure. All is well until I mouse over the ListView or select an item, when the color is changed based on the standard behavior of a ListView.
What would be the simplest/best way to disable the default row highlighting on mouse hover and selection?
--- Jim ---
Respuestas
Jimbo,
You should try somthing like:MyColor, in my case is a SolidColorBrush property of my underlying data object. It should work in your case also with the converter applied to your needs...<ControlTemplate TargetType="{x:Type ListViewItem}"> <Border Background="{Binding Path=MyColor}"> <GridViewRowPresenter /> </Border> </ControlTemplate>
- Marcado como respuestaJimbo Mx sábado, 07 de noviembre de 2009 19:42
Todas las respuestas
- Hi Jimbo,
You need to reset the control template for the listviewitem.
This should work fine:
Hope this helps.<Style TargetType="{x:Type ListViewItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <GridViewRowPresenter /> </ControlTemplate> </Setter.Value> </Setter> </Style>
Thanks for the response Stephanne, however with this I run into a problem in that my background setter on the style no longer works. Do I need to hook up the background setter/converter somewhere within the template?
<Style TargetType="{x:Type ListViewItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <GridViewRowPresenter /> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Background"> <Setter.Value> <Binding Path="MyField" Converter="{StaticResource MyConverter}" /> </Setter.Value> </Setter> </Style>Jimbo,
You should try somthing like:MyColor, in my case is a SolidColorBrush property of my underlying data object. It should work in your case also with the converter applied to your needs...<ControlTemplate TargetType="{x:Type ListViewItem}"> <Border Background="{Binding Path=MyColor}"> <GridViewRowPresenter /> </Border> </ControlTemplate>
- Marcado como respuestaJimbo Mx sábado, 07 de noviembre de 2009 19:42
- That did the trick! Thanks for saving me literally hours with my wheels spinning in the sand.
--- Jim ---

