2
int FadeOut;
        for (FadeOut = 90; FadeOut >= 10; FadeOut += -10)
        {
            this.Opacity = FadeOut / 100;
            this.refresh();
            System.Threading.Thread.Sleep(50);
        }

I did something like this but not working // this.refresh(); is not working

KirCats
  • 53
  • 6
  • 1
    You're getting a compile error because Refresh method doesn't even exit in [window class](http://msdn.microsoft.com/en-us/library/system.windows.window.aspx) ! – HichemSeeSharp Oct 09 '12 at 11:54

2 Answers2

1

I did something like this, and you can work on it.
Unfortunately you have to implement your own Window title bar :

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        Name="myWindow"  WindowStyle="None" AllowsTransparency="True"
        >
    <Window.Resources>
    </Window.Resources>
        <Grid>
        <Button Margin="337,0,0,155">
            <Button.Triggers>
                <EventTrigger  RoutedEvent="Button.Click">
                    <BeginStoryboard >
                        <Storyboard Duration="0:0:5">
                            <DoubleAnimation Storyboard.TargetName="myWindow" Storyboard.TargetProperty="Opacity" From="1" To="0"></DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>

    </Grid>
</Window>
HichemSeeSharp
  • 3,240
  • 2
  • 22
  • 44
1

Here's discussed the same problem.

Also you can use triggers: Event triggers or data triggers to initiate animation, and Completed event of animation to set callback on animation end. Here's data trigger (you should have FadeOut property in your data context)

<Window.Resources>
    <Storyboard x:Key="FadeOut">
        <DoubleAnimation From="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="0:0:1.5"/>
    </Storyboard>
</Window.Resources>
<Window.Style>
    <Style>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=FadeOut}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource FadeOut}"/>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Style>
Community
  • 1
  • 1
Ivan Leonenko
  • 2,363
  • 2
  • 27
  • 37