This can be done using animation. These include:
1) ObjectAnimationUsingKeyFrames , which sets the Visibility property to the target, with BeginTime of 0:0:.5 to delay this for half a second when the storyboard begins.
2) A DataTrigger that checks the property whose change will make the object visible (in this case, the IsChecked property on the CheckBox named Start ).
3) BeginStoryboard in DataTrigger.EnterActions , which starts the animation, and RemoveStoryboard in DataTrigger.ExitActions , which again makes the object invisible if the binding property returns.
Here is a simple working example:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <Storyboard x:Key="MakeObjectVisibleAfterHalfASecond"> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Duration="0" BeginTime="0:0:.5"> <DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </Page.Resources> <DockPanel> <CheckBox DockPanel.Dock="Top" Margin="10" x:Name="Start">Check this to make the label appear</CheckBox> <Border BorderThickness="2" BorderBrush="AliceBlue" CornerRadius="5" Margin="10" Padding="10" DockPanel.Dock="Top"> <Label Visibility="Hidden"> <Label.Content>This should appear a half second after the box is checked.</Label.Content> <Label.Style> <Style TargetType="Label"> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=Start, Path=IsChecked}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard Name="StartAnimation" Storyboard="{StaticResource MakeObjectVisibleAfterHalfASecond}"/> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <RemoveStoryboard BeginStoryboardName="StartAnimation"/> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </Label.Style> </Label> </Border> <TextBlock/> </DockPanel> </Page>
Note that you can also do this by omitting BeginTime and setting Duration to the animation, since the two are essentially the same with the keyframe animation.
Robert rossney
source share