I have an event fired when some button is being clicked
private void set_Opacity(object sender, RoutedEventArgs e)
{
this.Opacity = 0;
}
But there’s no effect when the button is clicked. What am I doing wrong?
Thanks.
EDIT :
I’ll give some background about what I am trying to do:
I have created a customized button that should minimize my window with a fade out animation so here’s the code of it:
private void minimize_Window(object sender, EventArgs e)
{
var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(1));
anim.Completed += (s, _) => this.Minimize();
this.BeginAnimation(UIElement.OpacityProperty, anim);
}
private void Minimize()
{
WindowState = WindowState.Minimized;
}
It works perfectly fine, though the problem is that when I try to retrieve my program from the task bar it won’t do anything (I am not able to see the program when I click on it from the taskbar after it minimized). What I understand from it is that the opacity of my program is being set to 0 while it got minimized(because of the animation).
So I used the Activated event calling that method:
private void set_Opacity(object sender, EventArgs e)
{
rectangle2.Opacity = 1;
WindowState = WindowState.Normal;
}
And still, same issue. Hope you could help.
Thank you very much.
The problem seems to be that in most cases,
thisis going to be aWindow. My assumption though, is that you are not trying to set the entire window to invisible, rather a Rectangle. You need to give your Rectangle a name usingx:Nameattribute. Here is an example:Then, in your button click:
If you really are trying to set the entire
Window‘s transparency:An entire Window can’t have it’s opacity set unless you specify
AllowTransparencyto true andWindowStyleto None in your XAML:Note the attributes being set.
EDIT:
Use the
Window.Activatedevent. From your XAML:And in your C#: