I have a ListView styled using the WhistlerBlue.xaml resource dictionary, as downlaoded from Codeplex: WPF DataGrid Themes from Silverlight.
I want alternating (odd & even) rows to have a different background colour.
I have added the following code to the default WhistlerBlue ListViewItem style (within the ControlTemplate.Triggers section):
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="AliceBlue"></Setter>
</Trigger>
I have also set the ListView style's AlternatingCount property to 2, but the alternating style triggers are still not working.
Any pointers would be greatly appreciated.
I've pasted the complete ListViewItemStyle below.
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ListViewItemFocusVisual}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="0,0,0,1" />
<Setter Property="Padding" Value="5,2,5,2" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{StaticResource OutsideFontColor}"/>
<Setter Property="Padding" Value="3" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<ControlTemplate.Resources>
<Storyboard x:Key="HoverOn">
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientOver" Storyboard.TargetProperty="Opacity" To="0.73"/>
</Storyboard>
<Storyboard x:Key="HoverOff">
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientOver" Storyboard.TargetProperty="Opacity" To="0"/>
</Storyboard>
<Storyboard x:Key="SelectedOn">
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientSelectedDisabled" Storyboard.TargetProperty="Opacity" To="1"/>
</Storyboard>
<Storyboard x:Key="SelectedOff">
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
<DoubleAnimation Duration="00:00:00.00" Storyboard.TargetName="BackgroundGradientSelectedDisabled" Storyboard.TargetProperty="Opacity" To="0"/>
</Storyboard>
</ControlTemplate.Resources>
<Border SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" x:Name="border">
<Grid Margin="0">
<Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2" Opacity="0"/>
<Rectangle x:Name="BackgroundGradientSelectedDisabled" Fill="{StaticResource grayGradient}" Stroke="#7F8E8F8F" RadiusX="2" RadiusY="2" Opacity="0"/>
<Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0"/>
<Rectangle x:Name="BackgroundHighlight" Margin="1" Stroke="#A0FFFFFF" RadiusX="1" RadiusY="1"/>
<GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,2,0,2" VerticalAlignment="Stretch" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="AliceBlue"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource HoverOff}" x:Name="HoverOff_BeginStoryboard"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource HoverOn}"/>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Trigger.ExitActions>
<BeginStoryboard x:Name="SelectedOff_BeginStoryboard" Storyboard="{StaticResource SelectedOff}"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard x:Name="SelectedOn_BeginStoryboard" Storyboard="{StaticResource SelectedOn}"/>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}" />
<Setter Property="Visibility" TargetName="BackgroundGradientSelected" Value="Hidden"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
<Condition Property="Selector.IsSelectionActive" Value="false" />
</MultiTrigger.Conditions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Apparently the ListViewItem ControlTemplate was overriding the style triggers for alternate row colours.
Since I was not using the storyboards in the ControlTemplate (I had set their Duration to 0), I solved the problem by just using Style Triggers, without styling the Template, as shown below.
<Style TargetType="{x:Type ListViewItem}" x:Key="ListViewItemStyle">
<Setter Property="FocusVisualStyle" Value="{StaticResource ListViewItemFocusVisual}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="5,2,5,2" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Height" Value="23px" />
<Setter Property="Foreground" Value="{StaticResource OutsideFontColor}"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="AliceBlue" />
<Setter Property="BorderBrush" Value="AliceBlue" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource BtnOverFill}" />
<Setter Property="BorderBrush" Value="{StaticResource selectedStroke}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#FFbbe9fd" />
</Trigger>
</Style.Triggers>
</Style>
I know this doesn't solve the problem if the ContolTemplate needs to be styled, but at least this was enough to satisfy my requirements.
Hope it helps somebody in the future.
At ExpressionDark.xaml for example:
find this: <Style TargetType="{x:Type ListViewItem}">
and find <Rectangle x:Name="Background"..
change the property value Fill to Fill="{TemplateBinding Background}"
and, inside the <ControlTemplate.Triggers> add this:
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#FF474A51"></Setter>
</Trigger>
Hope this helps anyone, else as beginner for wpf i am having hard time finding things specially i am on vb.net, very hard to get direct sample codes using mvvm, etc. :( cruel world.
Related
so im quite new to Wpf and was trying to animate something like this particular Animation:
Example
I found something like that to make an Colour Animation:
<EventTrigger
RoutedEvent="TextBox.MouseEnter">
<BeginStoryboard>
<Storyboard SlipBehavior="Slip">
<ColorAnimation Storyboard.TargetName="border"
Storyboard.TargetProperty="Background.Color"
To="Blue" Duration="00:00:00.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger
RoutedEvent="TextBox.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="border"
Storyboard.TargetProperty="Background.Color"
To="WhiteSmoke" Duration="00:00:00.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
Its just change the Color but I want to make it slide from left to right like the example, I know there is Blend to edit those kinda stuff. But I only know how to animate Objects to move but not how to slide the Color From Left to right.
My TextBox style looks like this now, could someone give me a Hint how to manage what I want to get?
<Style x:Key="TextBoxStyle1" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="FontSize" Value="8"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Border x:Name="border" Background="White" BorderBrush="#FF7D8683" CornerRadius="5" BorderThickness="0"/>
<ScrollViewer x:Name="PART_ContentHost" Margin="5,0,0,0" VerticalAlignment="Center" />
<Label Margin="5,0,0,0" x:Name="WaterMarkLabel" Content="{TemplateBinding Tag}" VerticalAlignment="Center"
Visibility="Collapsed" Foreground="Gray" FontFamily="Arial"/>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value=""/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="WaterMarkLabel" Value="Visible"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="DimGray"/>
</Trigger>
<EventTrigger
RoutedEvent="TextBox.MouseEnter">
<BeginStoryboard>
<Storyboard SlipBehavior="Slip">
<ColorAnimation Storyboard.TargetName="border"
Storyboard.TargetProperty="Background.Color"
To="Blue" Duration="00:00:00.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger
RoutedEvent="TextBox.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="border"
Storyboard.TargetProperty="Background.Color"
To="WhiteSmoke" Duration="00:00:00.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
I have added MouseEnter and MouseLeave event triggers and used DoubleAnimation to set the width:
<Page.Resources>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<Style x:Key="TextBoxStyle1" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
</Trigger>
<!-- Now we add the MouseEnter event.-->
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width" To="200" From="20" Duration="0:0:0:0.5" AccelerationRatio="0.5" DecelerationRatio="0.3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<!-- Now we add the MouseLeave event.-->
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width" To="20" Duration="0:0:0:0.5" AccelerationRatio="0.5" DecelerationRatio="0.3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<!-- That's all the codes we add to the default style.-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</Page.Resources>
I have this Style:
<Style x:Key="MenuBtn" TargetType="Button">
<Setter Property="Margin" Value="3"/>
<Setter Property="Background" Value="{DynamicResource PN_ColorFondoAcentoClaro}"/>
<Setter Property="Width" Value="240"/>
<Setter Property="Height" Value="55"/>
<Setter Property="FontFamily" Value="{DynamicResource PN_FontFamily}"/>
<Setter Property="FontSize" Value="{DynamicResource PN_FontSizeMediana}"/>
<Setter Property="Foreground" Value="{DynamicResource PN_ColorFuenteOscuro}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
BorderBrush="{DynamicResource PN_ColorFondoAcentoClaro}"
BorderThickness="0.5"
Background="{TemplateBinding Background}"
CornerRadius="5">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource PN_ColorAlerta}"/>
<Setter Property="BorderThickness" Value="10"/>
</Trigger>
<EventTrigger RoutedEvent="Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="220" Duration="0:0:0.7"
AccelerationRatio="0.10" DecelerationRatio="0.10"
Storyboard.TargetProperty="(Canvas.Width)" />
<DoubleAnimation Duration="0:0:0.7"
AccelerationRatio="0.10" DecelerationRatio="0.15"
Storyboard.TargetProperty="(Canvas.Width)" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard Storyboard="{StaticResource SetHoverBackgroundStoryboard}"/>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard Storyboard="{StaticResource RestoreBackgroundStoryboard}"/>
</EventTrigger>
<DataTrigger Binding="{Binding IsFavorite}" Value="True">
<Setter Property="Background" Value="{DynamicResource PN_ColorFondoAcentoClaro}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsFavorite}" Value="False">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I need to show some options, some ones are marked as favorites with IsFavorite property. I want to show a diferente color when IsFavorite is active. I used two datatriggers for it
<DataTrigger Binding="{Binding IsFavorite}" Value="True">
<Setter Property="Background" Value="{DynamicResource PN_ColorFondoAcentoClaro}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsFavorite}" Value="False">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
They works pretty well, but my mouse hover now shows nothing. Thats why I tryed
<Storyboard x:Key="SetHoverBackgroundStoryboard">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame
KeyTime="0:0:0"
Value="{StaticResource PN_ColorAlerta}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="RestoreBackgroundStoryboard">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame
KeyTime="0:0:0"
Value="{StaticResource PN_ColorFondoAcentoClaro}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
SetHoverBackgroundStoryboard sets my background like hover, but when I use RestoreBackgroundStoryboard don't know how to use IsFavorite to show my original color again.
There is a way to combine DataTrigger and EventTrigger to solve it?
How to avoid loose hover background effect when DataTrigger change my control background?
or
What I'm doing wrong?
You could use a DataTrigger to combine several conditions, for example that IsFavorite is true and IsMouseOver is also true:
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsFavorite}" Value="True" />
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red" />
</MultiDataTrigger>
I have a button style which I'm currently making. I want to trigger a smooth animation when the user clicks on the button. I need the two rectangle to be contained within the ControlTemplate as shown below.
The idea is that upon pressing the button, one of the rectangles fades out, and upon releasing it fades back in.
The triggers ARE being hit. I can prove this by adding a simple colour change for the buttons by doing the following before the Trigger.EnterActions:
<Setter TargetName="BackgroundNormal" Property="Fill" Value="Cyan" />
The storyboards seem not to trigger at all regardless of their content.
What am I doing wrong, please?
<Style x:Key="MyButton" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="{DynamicResource TextParagraphWhiteP1}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontWeight" Value="Light" />
<Setter Property="Background" Value="{DynamicResource Gradient_Playback_ButtonBase}" />
<Setter Property="MinHeight" Value="15" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="Padding" Value="6,2" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="BackgroundDepressed" Fill="Magenta" />
<Rectangle x:Name="BackgroundNormal" Fill="{DynamicResource Gradient_Playback_ButtonBase}" />
</Grid>
<ControlTemplate.Resources>
<Storyboard x:Key="PressDown">
<DoubleAnimation Storyboard.TargetName="BackgroundNormal" Storyboard.TargetProperty="(UIElement.Opacity)" To="0.0" Duration="0:0:0.1" />
</Storyboard>
<Storyboard x:Key="Release">
<DoubleAnimation Storyboard.TargetName="BackgroundNormal" Storyboard.TargetProperty="(UIElement.Opacity)" To="1.0" Duration="0:0:0.35" />
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressDown}" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsPressed" Value="false">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Release}" />
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I created my own button template which has a canvas inside which defines some gradients going over each other.
The basic button is grey
<Style x:Key="ButtonGrey" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Width" Value="200" />
<Setter Property="Height" Value="40" />
<Setter Property="FontSize" Value="24" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontFamily" Value="Utsaah" />
<Setter Property="Foreground" Value="#FFE6E7E8" />
<Setter Property="Margin" Value="0,0,0,2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border"
BorderThickness="2"
Margin="-2"
BorderBrush="{x:Null}" >
<Canvas x:Name="ButtonGreyCanvas">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="InvalidFocused"/>
<VisualState x:Name="InvalidUnfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!-- Button complex background -->
<Path x:Name="Bg1" Data="M0,40L200,40L200,0L0,0z" Stretch="Fill" Fill="{DynamicResource ButtonGreyBg1}" />
<Path x:Name="Bg2" Data="M0,40L200,40L200,0L0,0z" Stretch="Fill" Fill="{DynamicResource ButtonGreyBg2}" />
<!-- middle high dark strip -->
<Path x:Name="Bg3" Data="F1M200,20L0,20L0,40L200,40z" Fill="{DynamicResource ButtonGreyStripBg3}" Opacity="0.30000299215316772" Stretch="Fill" Canvas.Top="20" />
<ContentPresenter
Content="{TemplateBinding Content}"
Margin="40,8,0,0"/>
<ContentPresenter
Content="{TemplateBinding Content}"
TextBlock.Foreground="#1EE6E7E8"
Margin="41.5,6.8,0,0"/>
</Canvas>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter TargetName="Border" Property="BorderThickness" Value="1.3" />
<Setter TargetName="Border" Property="Margin" Value="-1.3" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
</Trigger>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderThickness" Value="2" />
<Setter TargetName="Border" Property="Margin" Value="-2" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
<Setter Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter TargetName="Border" Property="BorderThickness" Value="2" />
<Setter TargetName="Border" Property="Margin" Value="-2" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now I would just like to change the Bg1, Bg2 and Bg3 paths to different gradientBrush, so I created new style which inherite from ButtonGrey (called ButtonBlue), but I am not able to simply access to these paths (Bg1, Bg2 and Bg3) directly, like
<Style x:Key="ButtonBlue" TargetType="Button" BasedOn="{StaticResource ButtonGrey}">
<Setter TargetName="Bg1" ...???... />
</Style>
Can anyone help how to access to these paths on the canvas?
Thanks a lot!
I used the code from question Wpf treeview - i want to animate the expansion of the nodes, but the animation doesn't work on the first expand, it does work for the consequent expand events.
any ideas?
Here is a solution:
<Style x:Key="TreeViewItemStyle1" TargetType="{x:Type TreeViewItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="FontFamily" Value="Verdana"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="light"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Margin" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource grau80}"/>
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<ControlTemplate.Resources>
<Storyboard x:Key="Timeline1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ItemsHost">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.1" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetName="ItemsHost" Storyboard.TargetProperty="LayoutTransform.ScaleY" To="1" Duration="0:0:0.4">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="ItemsHost" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.5"/>
</Storyboard>
<Storyboard x:Key="Timeline2">
<DoubleAnimation Storyboard.TargetName="ItemsHost" Storyboard.TargetProperty="LayoutTransform.ScaleY" To="0" Duration="0:0:0.3">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="ItemsHost" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.4" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ItemsHost">
<DiscreteObjectKeyFrame KeyTime="0:0:0.4" Value="{x:Static Visibility.Visible}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="19" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ToggleButton x:Name="Expander" Style="{DynamicResource TB_Tree}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
<Border Name="Bd" Grid.Column="1" CornerRadius="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0.8" Padding="{TemplateBinding Padding}">
<ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="2,0"/>
</Border>
<ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Visibility="Collapsed" Opacity="0">
<ItemsPresenter.LayoutTransform>
<ScaleTransform ScaleY="0" />
</ItemsPresenter.LayoutTransform>
</ItemsPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="true">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Timeline1}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource Timeline2}"/>
</Trigger.ExitActions>
</Trigger>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="Expander" Property="Visibility" Value="Hidden"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="HasHeader" Value="false"/>
<Condition Property="Width" Value="Auto"/>
</MultiTrigger.Conditions>
<Setter TargetName="PART_Header" Property="MinWidth" Value="75"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="HasHeader" Value="false"/>
<Condition Property="Height" Value="Auto"/>
</MultiTrigger.Conditions>
<Setter TargetName="PART_Header" Property="MinHeight" Value="19"/>
</MultiTrigger>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Orange}"/>
<Setter Property="Foreground" Value="{DynamicResource weiss}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Orange}"/>
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource weiss}"/>
<Setter Property="Foreground" Value="{DynamicResource grau60}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource weiss}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Change the Trigger Value to false
and swap the EnterAction's storyboard to ExitAction's