Reputation: 4010
I have a rectangle with opacity 0 that covers a grid containing various controls. The idea is that this rectangle will fade in to hide the background controls at some point. At the moment, the rectangle is covering the controls and so you can't click on the controls as the click will be absorbed by the rectangle. Ideally, some way of completely disabling the rectangle from having any effect until the animation starts would best.
Here's a cut back version of the code I have:
XAML:
<Grid>
<Grid>
<Label Content="Some text" />
<Button Content="A button" Click="buttonClicked" />
</Grid>
<Rectangle x:Name="rectOverlay" Opacity="0" />
</Grid>
Cs:
using System.Windows.Media.Animation;
private void buttonClicked(object sender, RoutedEventArgs e)
{
rectOverlay.BeginAnimation(Rectangle.OpacityProperty, new DoubleAnimation(1, TimeSpan.FromSeconds(0.5)));
}
Upvotes: 2
Views: 691
Reputation: 4149
You could set the Visibility
of the Rectangle to Collapsed
, so that it doesn't eat mouse clicks. And you could set it back to Visible
in your buttonClicked
method.
Here is what I tried:
XAML:
<Grid>
<Grid>
<Label Content="Some text" />
<Button Content="A button" Click="ButtonBase_OnClick" />
</Grid>
<Rectangle x:Name="rectOverlay" Opacity="0" Fill="Green"/>
</Grid>
buttonClicked Code:
rectOverlay.Visibility = Visibility.Visible;
rectOverlay.BeginAnimation(Rectangle.OpacityProperty, new DoubleAnimation(1, TimeSpan.FromSeconds(0.5)));
Upvotes: 1