I'm simply trying to change the highlighted colour of a listviewitem in WPF. The solutions I've found online including Stackoverflow are having no effect on my listview. Am I going crazy? Am I missing something? Please show me how to do this. Here is my example code. The items are still showing the default blue.
<Window.Resources>
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static
SystemColors.HighlightBrushKey}" Color="Red" />
</Style.Resources>
</Style>
</Window.Resources>
<Grid>
<ListView VerticalAlignment="Top" Background="#2e2e2e"
Foreground="White">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static
SystemColors.HighlightTextBrushKey}"
Color="Red" />
<SolidColorBrush x:Key="{x:Static
SystemColors.HighlightBrushKey}"
Color="Purple" />
</Style.Resources>
</Style>
</ListView.ItemContainerStyle>
<ListViewItem Content="ITEM" />
<ListViewItem Content="ITEM" />
<ListViewItem Content="ITEM" />
<ListViewItem Content="ITEM" />
<ListViewItem Content="ITEM" />
</ListView>
<Button VerticalAlignment="Bottom" Height="50" />
</Grid>
You have to override the ControlTemplate of the ListViewItem. This way you can also design apart form the highlighting any other visual user interaction behavior and create transition animations.
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="HighlightTextBrushKey"
Color="Red" />
<SolidColorBrush x:Key="HighlightBrushKey"
Color="Purple" />
<SolidColorBrush x:Key="HighlightMouseOverBrushKey"
Color="{Binding Source={StaticResource HighlightBrushKey}, Path=Color}"
Opacity="0.3" />
</Style.Resources>
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
Margin="{TemplateBinding Margin}">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource HighlightBrushKey}"/>
<Setter Property="Foreground" Value="{StaticResource HighlightTextBrushKey}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource HighlightMouseOverBrushKey}"/>
<Setter Property="Foreground" Value="{StaticResource HighlightTextBrushKey}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
An alternative to the triggers you can animate transitions with the help of the VisualStateManager
Related
I have applied the evernote tag control which is working but the design is not in multi line as I add tag it is added next to the previous tag and adding in the single line, but it has to move down when there is no more space on the page. Here is the screenshot of what I want:
I have followed this link : http://stackoverflow.com/questions/15167809/how-can-i-create-a-tagging-control-similar-to-evernote-in-wpf but still unable to get the tags in multi line. Please let me know where I am going wrong. Following is my xaml:
<!-- EvernoteTagControl default style -->
<Style TargetType="{x:Type local:EvernoteTagControl}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="White" />
<LinearGradientBrush x:Key="IconBrush" EndPoint="0,1">
<GradientStop Color="#5890f0" Offset="0" />
<GradientStop Color="#0351d7" Offset="1" />
</LinearGradientBrush>
</Style.Resources>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Margin" Value="15 25 15 15" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:EvernoteTagControl}">
<Grid>
<Grid.ColumnDefinitions>
<!--<ColumnDefinition Width="Auto" />-->
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!--<Path Grid.Column="0" Margin="2" Fill="{StaticResource IconBrush}" Height="19" Stretch="Uniform" Data="M 50.535714,0.44196425 0.00446427,34.754464 l 0,106.906246 100.71874573,0 0,-107.124996 L 50.535714,0.44196425 z m 0.1875,21.21874975 c 6.311826,0 11.40625,5.094424 11.40625,11.40625 0,6.311826 -5.094424,11.4375 -11.40625,11.4375 -6.311826,0 -11.4375,-5.125674 -11.4375,-11.4375 0,-6.311826 5.125674,-11.40625 11.4375,-11.40625 z" />-->
<ItemsPresenter Grid.Column="0" Margin="2" />
<Button Margin="5,0,0,0" Grid.Column="1" Content="Click to add..." x:Name="PART_CreateTagButton">
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter TextElement.Foreground="#FF555555" VerticalAlignment="Center" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEditing" Value="True">
<Setter TargetName="PART_CreateTagButton" Property="Visibility" Value="Collapsed" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel" >
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- EvernoteTagItem default style -->
<Style TargetType="{x:Type local:EvernoteTagItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="MinWidth" Value="50" />
<Setter Property="Margin" Value="0,0,2,0" />
<Setter Property="Padding" Value="5,2,0,2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:EvernoteTagItem}">
<Button x:Name="PART_TagButton" Content="{TemplateBinding Text}" Foreground="#ffffff" Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}" BorderBrush="#00698C" BorderThickness="1" CornerRadius="2" Background="#00698C" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,0,2" />
<Button x:Name="PART_DeleteTagButton" Grid.Column="1" Margin="3,0" VerticalAlignment="Center" HorizontalAlignment="Right" >
<Button.Template>
<ControlTemplate>
<Grid Height="10" Width="10" Background="#00698C" >
<Path Stretch="Uniform" ClipToBounds="True" Stroke="{StaticResource HighlightBrush}" StrokeThickness="1" Data="M 85.364473,6.9977109 6.0640998,86.29808 6.5333398,85.76586 M 6.9926698,7.4977169 86.293043,86.79809 85.760823,86.32885" />
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Border>
<!--<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#ffffff" />
<Setter TargetName="PART_DeleteTagButton" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>-->
</ControlTemplate>
</Button.Template>
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEditing" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:EvernoteTagItem}">
<tkInput:AutoCompleteBox x:Name="PART_InputBox"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ItemsSource="{Binding AllTags, RelativeSource={RelativeSource AncestorType={x:Type local:EvernoteTagControl}}}"
IsTextCompletionEnabled="True"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
I am getting these tags as:
Currently, you use a StackPanel as ItemsPanel, but a stack panel will never wrap its items in multiple dimensions. So instead, you should try panels like WrapPanel or UniformGrid
For the WrapPanel, you also need to set a Width in the ItemContainerStyle in order to assure same size for all tag items (according to your "what I want" picture).
Then you have to decide on the positioning of your PART_CreateTagButton button. With multi lines of tags, the grid layout of ItemsPresenter and PART_CreateTagButton might no longer be appropriate.
You can probably create a compound items source of the original tag items source and the button as last item. This way, the button will always be properly aligned with the tags. See Add extra items when using ItemsSource and How do you bind a CollectionContainer to a collection in a view model? for more details.
I need the area series charting to look like:
I succeeded in hiding the two axis and changing the colors to gradient brush.
I still need help on changing the opacity so the green one will be "behind" the orange one.
Also - How do I change the little points on the graph?
How do I change the background to be transparent?
How to hide the chart title?
Right now it looks like this:
Any help will be very appreciated!
Here is my xaml code:
<LinearGradientBrush x:Key="GreenGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#77b31a" Offset="0.75"></GradientStop>
<GradientStop Color="#85d805" Offset="0.45"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="OrangeGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#fff92900" Offset="0.75"></GradientStop>
<GradientStop Color="#ffff6115" Offset="0.45"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="GreenAreaSeriesStyle" TargetType="Control">
<Setter Property="Background" Value="{StaticResource GreenGradientBrush}" />
<Setter Property="Opacity" Value="1"></Setter>
</Style>
<Style x:Key="OrangeAreaSeriesStyle" TargetType="Control">
<Setter Property="Background" Value="{StaticResource OrangeGradientBrush}" />
<Setter Property="Opacity" Value="1"></Setter>
</Style>
<datavis:ResourceDictionaryCollection x:Key="MyPalette">
<ResourceDictionary>
<Style x:Key="DataPointStyle" BasedOn="{StaticResource GreenAreaSeriesStyle}" TargetType="Control" >
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" BasedOn="{StaticResource OrangeAreaSeriesStyle}" TargetType="Control" >
</Style>
</ResourceDictionary>
</datavis:ResourceDictionaryCollection>
<Style x:Key ="PerformanceChartMajorTickMarkStyle" TargetType="Line">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</Window.Resources>
<charting:Chart Palette="{StaticResource MyPalette}" HorizontalAlignment="Left" Margin="39,38,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Top" Width="815" Height="598" OverridesDefaultStyle="False">
<charting:Chart.LegendStyle>
<Style TargetType="datavis:Legend">
<Setter Property="Width" Value="0" />
</Style>
</charting:Chart.LegendStyle>
<charting:AreaSeries Name="Green" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" >
<charting:AreaSeries.IndependentAxis>
<charting:CategoryAxis Orientation="X" Visibility="Hidden"/>
</charting:AreaSeries.IndependentAxis>
<charting:AreaSeries.DependentRangeAxis>
<charting:LinearAxis Orientation="Y" Visibility="Hidden"/>
</charting:AreaSeries.DependentRangeAxis>
</charting:AreaSeries>
<charting:AreaSeries Name="Orange" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True">
<charting:AreaSeries.IndependentAxis>
<charting:CategoryAxis Orientation="X" Visibility="Hidden"/>
</charting:AreaSeries.IndependentAxis>
<charting:AreaSeries.DependentRangeAxis>
<charting:LinearAxis Orientation="Y" Visibility="Hidden"/>
</charting:AreaSeries.DependentRangeAxis>
</charting:AreaSeries>
</charting:Chart>
I posted a similar question and got the following answer, which really helped me.
<ch:Chart Margin="56,21,50,72" Title="MyChart" DataContext="{Binding ElementName=Window, Mode=OneWay}" Style="{StaticResource controlStyle}" >
<ch:AreaSeries Name="DefaultArea" ItemsSource="{Binding Path=Key}" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" Opacity="1" Title="111111" >
<ch:AreaSeries.Style>
<Style TargetType="ch:AreaSeries">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ch:AreaSeries">
<Canvas x:Name="PlotArea">
<Path Data="{TemplateBinding Geometry}" StrokeThickness="3" Fill="Pink" Style="{TemplateBinding PathStyle}" Opacity="1" />
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ch:AreaSeries.Style>
</ch:AreaSeries>
<ch:AreaSeries Name="PersonnelArea" ItemsSource="{Binding Path=Key}" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" Opacity="1" >
<ch:AreaSeries.Style>
<Style TargetType="ch:AreaSeries">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ch:AreaSeries">
<Canvas x:Name="PlotArea">
<Path Data="{TemplateBinding Geometry}" StrokeThickness="3" Fill="Yellow" Style="{TemplateBinding PathStyle}" Opacity="1" />
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ch:AreaSeries.Style>
</ch:AreaSeries>
</ch:Chart>
You can also set the style as Ressource in XAML and then assign it dynamically in the code behind.
Here my original question with the Answer:
WPF AreaSeries: How to change background opacity?
I'm overriding my tooltips with the following:
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid>
<Grid.Background>
<SolidColorBrush />
</Grid.Background>
<mwt:SystemDropShadowChrome Color="#00FFFFFF" CornerRadius="5" Name="Shdw" SnapsToDevicePixels="True">
<Border CornerRadius="5">
<StackPanel>
<ContentPresenter TextBlock.Foreground="Black" />
</StackPanel>
</Border>
</mwt:SystemDropShadowChrome>
</Grid>
The Thickness value for the margin seems to have a maximum value of 5?
<ControlTemplate.Triggers>
<Trigger Property="ToolTipService.HasDropShadow">
<Setter Property="FrameworkElement.Margin" TargetName="Shdw">
<Setter.Value>
<Thickness>0,0,5,5</Thickness>
</Setter.Value>
</Setter>
<Trigger.Value>
<sys:Boolean>True</sys:Boolean>
</Trigger.Value>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
It would be nice to be able to see more of the dropshadow.
My bad for not posting all my code. Here it is with an edit based on the response from icebat:
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid>
<Grid.Background>
<SolidColorBrush />
</Grid.Background>
<mwt:SystemDropShadowChrome Color="#71000000" CornerRadius="5" Name="Shdw" SnapsToDevicePixels="True">
<Border CornerRadius="5">
<StackPanel>
<ContentPresenter TextOptions.TextRenderingMode="ClearType" TextOptions.TextFormattingMode="Display" TextBlock.FontFamily="Segoe UI" TextBlock.FontStretch="Normal" TextBlock.FontWeight="Normal" TextBlock.Foreground="Black" TextBlock.FontSize="13" Margin="18,8,16,4" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Border HorizontalAlignment="Stretch" BorderThickness="0,1,0,0" BorderBrush="Gray" Margin="10,5,10,5" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">
<TextBlock Margin="8,4,0,0" FontWeight="Bold" Text="{x:Static res:AppStrings.Help_0_Footer}" FontSize="13" Foreground="#E3000000" />
</Border>
</StackPanel>
<Border.Background>
<LinearGradientBrush>
<LinearGradientBrush.StartPoint>
<Point X=".5" Y="0"/>
</LinearGradientBrush.StartPoint>
<LinearGradientBrush.EndPoint>
<Point X=".5" Y="1"/>
</LinearGradientBrush.EndPoint>
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFFFA200" Offset="1"/>
<GradientStop Color="White" Offset="0.305"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
</Border>
</mwt:SystemDropShadowChrome>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ToolTipService.HasDropShadow" Value="True">
<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I still don't get a thicker dropshadow for a margin larger than 5.
Margin is not limited. To see more of the shadow you need to apply margin not to the SystemDropShadowChrome decorator itself but to its content:
<mwt:SystemDropShadowChrome Name="Shdw" CornerRadius="5">
<Border Name="shdwContent" CornerRadius="5">
<StackPanel>
<ContentPresenter TextBlock.Foreground="Black" />
</StackPanel>
</Border>
</mwt:SystemDropShadowChrome>
...
<ControlTemplate.Triggers>
<Trigger Property="ToolTipService.HasDropShadow" Value="True">
<Setter Property="Margin" TargetName="ShdwContent" Value="0,0,5,5">
</Trigger>
</ControlTemplate.Triggers>
And as a side note, right now you are using transparent color as shadow color (#00FFFFFF). If that`s not changed with some triggers or by other means, you won`t see any shadow.
A question about dragging and dropping tree view items in WPF.
My original question is a little complex. So I simplified it, and here is the code:
XAML
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TreeView>
<TreeView.ItemContainerStyle>
<Style>
<Setter Property="TreeViewItem.IsExpanded" Value="True"/>
<Setter Property="TreeViewItem.Background" Value="LightBlue"/>
<Setter Property="TreeViewItem.AllowDrop" Value="True"/>
<EventSetter Event="TreeViewItem.MouseMove" Handler="TreeNode_MouseMove"/>
<EventSetter Event="TreeViewItem.Drop" Handler="TreeNode_Drop"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeViewItem Header="first node in the tree"/>
<TreeViewItem Header="second node in the tree"></TreeViewItem>
<TreeViewItem Header="third node in the tree"></TreeViewItem>
</TreeView>
</Grid>
And code-behind:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void TreeNode_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragDrop.DoDragDrop(this, DateTime.Now.ToString(), DragDropEffects.Move);
}
}
private void TreeNode_Drop(object sender, DragEventArgs e)
{
string str = (string)e.Data.GetData(typeof(string));
MessageBox.Show(str);
}
}
So what I want to do is very simple, just pop up a message box when one tree view item is dragged and dropped on another tree view item.
When I drop it right on another item, it works fine, like this:
But if I drag it slightly off the boundary of the item, it does not work, like this:
The mouse cursor is displayed as a “forbidden sign”, sorry I can’t get it in the screen shot.
So now my question is: how to make the second condition work? How to make the Drop event still fire up when the dropping location is slightly off the boundary of the item?
Thanks in advance.
Take the default ControlTemplate of TreeViewItem and make the Border (the border which contains the ContentPresenter) to have a colspan of 2, e.g.:
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="Bd"
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="2">
Note that the whole area in TreeViewItem next to the TextBlock would become clickable. You may want to play around with the template to fit it to your needs.
Below is the ControlTemplate of TreeViewItem extracted using Dump Control Template Utility.
<?xml version="1.0" encoding="utf-16"?>
<ControlTemplate
TargetType="TreeViewItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="Auto"
MinWidth="19" />
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ToggleButton
IsChecked="False"
ClickMode="Press"
Name="Expander">
<ToggleButton.Style>
<Style
TargetType="ToggleButton">
<Style.Resources>
<ResourceDictionary />
</Style.Resources>
<Setter
Property="UIElement.Focusable">
<Setter.Value>
<s:Boolean>False</s:Boolean>
</Setter.Value>
</Setter>
<Setter
Property="FrameworkElement.Width">
<Setter.Value>
<s:Double>19</s:Double>
</Setter.Value>
</Setter>
<Setter
Property="FrameworkElement.Height">
<Setter.Value>
<s:Double>13</s:Double>
</Setter.Value>
</Setter>
<Setter
Property="Control.Template">
<Setter.Value>
<ControlTemplate
TargetType="ToggleButton">
<Border
Background="#00FFFFFF"
Width="19"
Height="13">
<Border
BorderThickness="1,1,1,1"
CornerRadius="1,1,1,1"
BorderBrush="#FF7898B5"
Width="9"
Height="9"
SnapsToDevicePixels="True">
<Border.Background>
<LinearGradientBrush
StartPoint="0,0"
EndPoint="1,1">
<LinearGradientBrush.GradientStops>
<GradientStop
Color="#FFFFFFFF"
Offset="0.2" />
<GradientStop
Color="#FFC0B7A6"
Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Path
Data="M0,2L0,3 2,3 2,5 3,5 3,3 5,3 5,2 3,2 3,0 2,0 2,2z"
Fill="#FF000000"
Name="ExpandPath"
Margin="1,1,1,1" />
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger
Property="ToggleButton.IsChecked">
<Setter
Property="Path.Data"
TargetName="ExpandPath">
<Setter.Value>
<StreamGeometry>M0,2L0,3 5,3 5,2z</StreamGeometry>
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>True</s:Boolean>
</Trigger.Value>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="Bd"
SnapsToDevicePixels="True"
Grid.Column="1">
<ContentPresenter
Content="{TemplateBinding HeaderedContentControl.Header}"
ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"
ContentSource="Header"
Name="PART_Header"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
<ItemsPresenter
Name="ItemsHost"
Grid.Column="1"
Grid.Row="1"
Grid.ColumnSpan="2" />
</Grid>
<ControlTemplate.Triggers>
<Trigger
Property="TreeViewItem.IsExpanded">
<Setter
Property="UIElement.Visibility"
TargetName="ItemsHost">
<Setter.Value>
<x:Static
Member="Visibility.Collapsed" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>
<Trigger
Property="ItemsControl.HasItems">
<Setter
Property="UIElement.Visibility"
TargetName="Expander">
<Setter.Value>
<x:Static
Member="Visibility.Hidden" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>
<Trigger
Property="TreeViewItem.IsSelected">
<Setter
Property="Panel.Background"
TargetName="Bd">
<Setter.Value>
<DynamicResource
ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
</Setter.Value>
</Setter>
<Setter
Property="TextElement.Foreground">
<Setter.Value>
<DynamicResource
ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>True</s:Boolean>
</Trigger.Value>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
Property="TreeViewItem.IsSelected">
<Condition.Value>
<s:Boolean>True</s:Boolean>
</Condition.Value>
</Condition>
<Condition
Property="Selector.IsSelectionActive">
<Condition.Value>
<s:Boolean>False</s:Boolean>
</Condition.Value>
</Condition>
</MultiTrigger.Conditions>
<Setter
Property="Panel.Background"
TargetName="Bd">
<Setter.Value>
<DynamicResource
ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
</Setter.Value>
</Setter>
<Setter
Property="TextElement.Foreground">
<Setter.Value>
<DynamicResource
ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
</Setter.Value>
</Setter>
</MultiTrigger>
<Trigger
Property="UIElement.IsEnabled">
<Setter
Property="TextElement.Foreground">
<Setter.Value>
<DynamicResource
ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
use AllowDrop property and Drop event for TreeView itself.
this is from msdn: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4b8bafe5-ae3e-439d-953a-f534a60dbb2d/
I have a ListView containing some ListViewItems. By default, selecting items makes their background to some deep blue. I would like to apply a style such that selecting an item does not change its look.
In my xaml I already achieved this:
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</Style.Resources>
</Style>
Unfortunately, this does not do the trick. It just simply makes the selection white instead of blue.
Does anyone have an idea?
Best wishes,
Christian
EDIT:
Sample Code:
<Window.Resources>
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</Style.Resources>
</Style>
</Window.Resources>
<ListView x:Name="lvTestRun" ItemsSource="{Binding Path=TestRunData}" Margin="177,26,8,53.277" SelectionMode="Multiple">
<ListView.View>
<GridView>
<GridViewColumn Header="Status"/>
<GridViewColumn Header="Duration"/>
<GridViewColumn Header="Start Time"/>
<GridViewColumn Header="End Time"/>
</GridView>
</ListView.View>
</ListView>
In order to reproduce this, you may have to set the background color of a single ListViewItem to something like green or red.
I'm not sure I understand what you mean by white instead of blue. When a ListViewItem is selected the foreground and background is changed by a trigger. To change the foreground of a ListViewItem you can use this
<ListView ...>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Resources>
<!-- Foreground for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black"/>
<!-- Background for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent"/>
</Style.Resources>
</Style>
</ListView.ItemContainerStyle>
...
</ListView>
Update
Try this for re-templating. I removed all triggers for selected
<ListView ...>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Resources>
<LinearGradientBrush x:Key="ListItemHoverFill" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF1FBFF" Offset="0"/>
<GradientStop Color="#FFD5F1FE" Offset="1"/>
</LinearGradientBrush>
</Style.Resources>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border CornerRadius="2" SnapsToDevicePixels="True"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<Border Name="InnerBorder" CornerRadius="1" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="11" />
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Name="UpperHighlight" Visibility="Collapsed" Fill="#75FFFFFF" />
<GridViewRowPresenter Grid.RowSpan="2"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ListItemHoverFill}" />
<Setter Property="BorderBrush" Value="#FFCCF0FF" />
<Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" />
</Trigger>
<!--<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource ListItemSelectedFill}" />
<Setter Property="BorderBrush" Value="#FF98DDFB" />
<Setter TargetName="InnerBorder" Property="BorderBrush" Value="#80FFFFFF" />
<Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" />
<Setter TargetName="UpperHighlight" Property="Fill" Value="#40FFFFFF" />
</Trigger>-->
<!--<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource ListItemSelectedInactiveFill}" />
<Setter Property="BorderBrush" Value="#FFCFCFCF" />
</MultiTrigger>-->
<!--<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource ListItemSelectedHoverFill}" />
<Setter Property="BorderBrush" Value="#FF98DDFB" />
</MultiTrigger>-->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Have a look at this: http://www.wpftutorial.net/ListBoxSelectionBackground.html or http://dotnetbutchering.blogspot.be/2009/08/how-to-set-wpf-listview-selected-item.html -the same principle applies for the ListView control.
For example, the following triggers based code should do the trick and imitate no change of colour when the selection is changed.
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true" >
<Setter Property="Foreground" Value="YourForegroundColour" />
<Setter Property="Background" Value="YourBackgroundColour" />
</Trigger>
</Style.Triggers>
</Style>
What I normally do is define that color in the listview's resource collection. Then for each item I can define a template with the colors I like and when I select I don't get the blue.
I do think you should have some sort of indication that an item is selected though.
For also disabling inactive style,
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>