Custom SelectedItem in ListView
-
Hello, i am very new to WPF and so far i like it more than WinForms. Currently i have a template for ListViewItems. And i want to change the selected style. When i select an item, i see blue background. Can anyone tell me where shoud i look into?
-
Hello, i am very new to WPF and so far i like it more than WinForms. Currently i have a template for ListViewItems. And i want to change the selected style. When i select an item, i see blue background. Can anyone tell me where shoud i look into?
In WPF, the selected item background colour is determined by System.HighlightBrush. This means that you can define a brush for the style and use SystemColors.HighlightBrushKey to set this. Here's a sample:
<Style TargetType='ListViewItem'>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
</Style.Resources>
</Style>"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
In WPF, the selected item background colour is determined by System.HighlightBrush. This means that you can define a brush for the style and use SystemColors.HighlightBrushKey to set this. Here's a sample:
<Style TargetType='ListViewItem'>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
</Style.Resources>
</Style>"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Wow, thank you. I didn't ever knew it was possible to override system colors
-
Wow, thank you. I didn't ever knew it was possible to override system colors
You are most welcome. Ain't WPF cool?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
You are most welcome. Ain't WPF cool?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Pete O'Hanlon wrote:
Ain't WPF cool?
I am asking mysely: Why didn't i tried this before Now i have a diffrent problem. I do not think it is alrigt to contiune new post, but here it is: This is a stripped down event Template for a ListViewItem template
<DataTemplate x:Key="ListBoxItemPodjetjeTemplate"> <Grid Margin="2"> <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0" Background="#8098D8D8" CornerRadius="4,4,4,4"/> </Grid> <DataTemplate.Triggers> <Trigger Property="Control.IsMouseOver"> <Setter Property="Control.Background" Value="LightGreen"/> </Trigger> </DataTemplate.Triggers> </DataTemplate>
I put Highlight color to transparent, now i want to change background of an item based on mouse over. Now the trigger is throwing me an exception with an inner text: {"'{DependencyProperty.UnsetValue}' is not a valid value for property 'IsMouseOver'."}. Thank you in advance
-
Pete O'Hanlon wrote:
Ain't WPF cool?
I am asking mysely: Why didn't i tried this before Now i have a diffrent problem. I do not think it is alrigt to contiune new post, but here it is: This is a stripped down event Template for a ListViewItem template
<DataTemplate x:Key="ListBoxItemPodjetjeTemplate"> <Grid Margin="2"> <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0" Background="#8098D8D8" CornerRadius="4,4,4,4"/> </Grid> <DataTemplate.Triggers> <Trigger Property="Control.IsMouseOver"> <Setter Property="Control.Background" Value="LightGreen"/> </Trigger> </DataTemplate.Triggers> </DataTemplate>
I put Highlight color to transparent, now i want to change background of an item based on mouse over. Now the trigger is throwing me an exception with an inner text: {"'{DependencyProperty.UnsetValue}' is not a valid value for property 'IsMouseOver'."}. Thank you in advance
What value are you applying? You haven't actually set one in the Trigger. Try changing it to
<Trigger Property="Control.IsMouseOver" Value="True" />
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
What value are you applying? You haven't actually set one in the Trigger. Try changing it to
<Trigger Property="Control.IsMouseOver" Value="True" />
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Aw stupid me. Thank you for your reply
-
Aw stupid me. Thank you for your reply
No problems - it's easy to miss something like this. As a hint, if you ever see a message about
DependencyProperty.UnsetValue
then it means the value the DP expects hasn't been set. This isn't the same as a null value because null might be a legitimate value for the DP."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.