Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to set the background in a listview?

$
0
0

I would like to set the background of the ítems in a listview to transparent because I will set the background with a converter.

I am doing this with datagrids and works, and the way tha I am using is:

<DataGrid Name="myDatagrid"
	Style="{StaticResource DataGridCustomBackground}"><DataGrid.RowStyle><Style TargetType="DataGridRow"><Setter Property="Background"><Setter.Value><MultiBinding Converter="{StaticResource myDataGridBackgroundMultivalueConverter}"><MultiBinding.Bindings><Binding /><Binding RelativeSource="{RelativeSource Self}" Path="IsSelected"/></MultiBinding.Bindings></MultiBinding></Setter.Value></Setter></Style></DataGrid.RowStyle></Datagrid>


And I have a resourcedictionary:

<Style TargetType="{x:Type DataGrid}" x:Key="DataGridCustomBackground"><Setter Property="IsReadOnly" Value="true"/><Setter Property="CanUserAddRows" Value="false"/><Setter Property="CanUserDeleteRows" Value="true"/><Setter Property="AutoGenerateColumns" Value="false"/><Setter Property="VerticalScrollBarVisibility" Value="Visible"/><Setter Property="HorizontalScrollBarVisibility" Value="Visible"/><Setter Property="CanUserSortColumns" Value="true"/><Style.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black"/></Style.Resources></Style>

The idea is to set transparent the default system colors to avoid to hide the background that I set in the converter.

I am trying to do the same with a listview, but it does not work. I do this:

<ListView Name"MyListView"
	Style="{StaticResource ListViewCustomBackground}"><ListView.ItemContainerStyle><Style TargetType="ListBoxItem"><Setter Property="Background"><Setter.Value><MultiBinding Converter="{StaticResource myListBoxItemsBackgroundMultivalueConverter}"><MultiBinding.Bindings><Binding /><Binding ElementName="ucPrincipal" Path="DataContext.MyProperty1"/><Binding ElementName="ucPrincipal" Path="DataContext.MyProperty2"/></MultiBinding.Bindings></MultiBinding></Setter.Value></Setter></Style></ListView.ItemContainerStyle></listView>

And the resource:

<Style TargetType="{x:Type ListViewItem}" x:Key="ListViewItemCustomBackground"><Style.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent"/><SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black"/></Style.Resources></Style>

But in this case, the backgroud is hidden, I need to deselect the ítem to see the background that I set. The background is set correctly, but is hidden.

Thank so much.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>