I am trying to fade in a control when it becomes visible. The following compiles and runs fine, it just doesn’t fade in (control instantly appears when IsActive is set to true)
<UserControl x:Class="blah"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:util="clr-namespace:blah.Util"
mc:Ignorable="d"
d:DesignHeight="250" d:DesignWidth="400">
<UserControl.Resources>
<util:BooleanToVisibilityConverter x:Key="BoolToVis" />
<Style TargetType="UserControl">
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:1.25" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<UserControl.Visibility>
<Binding Path="IsActive" Converter="{StaticResource ResourceKey=BoolToVis}" ConverterParameter="False" />
</UserControl.Visibility>
<!-- Snip rest of simple control -->
</UserControl>
Firstly, I’d be grateful if anyone could tell me why this isn’t working.
Secondly I was wondering if there is any way to debug such things, as I often find myself trying to get triggers working properly. Currently my debugging consists of staring at the XAML to try and see what’s wrong, or randomly changing bits to try and narrow down the area.
What I really want to do it put a breakpoint on the <Trigger Property="Visibility" Value="Visible"> bit, to see if that is being triggered as a starting point. Obviously I can’t do this but was wondering if there’s any way to do more structured debugging rather than my current random poking at a blank wall. :-/
Set
UserControl.Visibilityin Style or you will override theStyle.Triggerif you set the Visibility property explicitly.