I have an ImageBrush within a Rectangle that I'm trying to fade in on load, by increasing the opacity from 0 to 100.
Here's what I have:
<Rectangle HorizontalAlignment="Left" Width="200" Stroke="#FF000000" StrokeThickness="0" Fill="{DynamicResource MyImageBrush}" >
<Rectangle.Resources>
<ImageBrush x:Name="ImgBrush" x:Key="MyImageBrush" ImageSource="tower.jpg" Stretch="UniformToFill" Opacity="0" >
</ImageBrush>
</Rectangle.Resources>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation x:Name="FadeIn" Storyboard.TargetName="ImgBrush" Storyboard.TargetProperty="Opacity" From="0" To="100" Duration="0:0:5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
The error that is thrown is:
'ImgBrush' name cannot be found in the name scope of 'System.Windows.Shapes.Rectangle'
(ImgBrush being specified in Storyboard.TargetName)
What can I do to resolve this?