I have a ListView which shows a collection of objects. I want to disable the "Blue effect" or "Blue rectangle" when clicking on the ListViewItem, and Let only the object in this Item enabled. Does anyone has an idea about that ??
Here is an Example of one of my ListViewItems:
Here is my listView:
<ListView SelectionMode="Single" IsManipulationEnabled="True" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding ChildrenList}" Background="Transparent" BorderBrush="Transparent" >
<ListView.LayoutTransform>
<RotateTransform Angle="{Binding IsVertical, Converter={StaticResource AngleOfBool}}"></RotateTransform>
</ListView.LayoutTransform>
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Background="Transparent" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox Content="{Binding Id}" Height="auto" Name="Flag" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" IsChecked="{Binding IsVisible}"/>
<Grid Grid.Column="1">
<area:Area HorizontalAlignment="Stretch" Visibility="{Binding IsVisible, Converter={StaticResource VisibilityOfBool}}" />
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Setting the
IsEnabled
property of a parent control toFalse
will automatically set theIsEnabled
property of every child control toFalse
as well. The only way around this is to set theIsEnabled
property of the individual controls that you want to be disabled toFalse
, instead of that of the parent control.However, you can create one
bool
property toBind
to theIsEnabled
property of all of the relevant controls so that at least, you can disable and enable them all using the one property:Using this method, only the controls using the
AreInnerControlsEnabled
property will be affected.UPDATE >>>
So it turns out that you actually want to remove the default selection colour of the
ListView
... that is very different to what you 'appeared' to be asking. However, now I know that, you can achieve that very easily by using a simpleStyle
:You only need one of these to hide that colour, but I have shown you the rest for future reference. You can use it like this:
As I stated at the comments, I would change the ListViewItem template.
The code is very verbose, so let's do it:
First, create a ResourceDictionary and set a reference to it in you
App.xaml
.Having done that, paste the code below at the ResourceDictionary:
Notice that the first 6 tags (
SolidColorBrush
) have the references to the colors according to the state of the ListViewItem.From here, you can take 2 paths, change the
SolidColorBrush
Color to whatever you want to, in your caseTransparent
OR remove theTriggers
altogether (not recommended).When you're done, set the
Style
property of your ListBoxItem to thex:Key
you named. In the code the name isx:Key="ListViewItemStyle1"
.I hope that this guide you!