WPF登录提示窗体实现原理

主要实现系统登录时登录信息的提示,增加更好的用户体验,避免假死和长时间的未响应。 前台代码(XAML

 

    <Window.Resources>

        <Storyboard x:Key="ImageStoryBoard">

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"

            Storyboard.TargetName="image"RepeatBehavior="Forever">

                <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="90"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="180"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="270"/>

                <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="360"/>

            </DoubleAnimationUsingKeyFrames>

        </Storyboard>

        <Storyboard x:Key="showStoryBoard">

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" Storyboard.TargetName="txtb_option">

                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1"/>

            </DoubleAnimationUsingKeyFrames>

        </Storyboard>

 

        <Storyboard x:Key="hideStoryBoard">

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" Storyboard.TargetName="txtb_option">

                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1"/>

                <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="0"/>

            </DoubleAnimationUsingKeyFrames>

        </Storyboard>

    </Window.Resources>

    <Window.Template>

        <ControlTemplate TargetType="{x:Type Window}">

            <Border CornerRadius="10">

                <ContentPresenter/>

            </Border>

        </ControlTemplate>

    </Window.Template>

    <Border CornerRadius="5" Margin="5" BorderBrush="Transparent" BorderThickness="0">

        <Border.Background>

            <ImageBrush ImageSource="Images/bg_main.jpg"/>

        </Border.Background>

        <Grid Height="200" Width="450">

            <Grid.RowDefinitions>

                <RowDefinition/>

                <RowDefinition Height="Auto"/>

                <RowDefinition Height="Auto"/>

                <RowDefinition/>

            </Grid.RowDefinitions>

            <TextBlock Text="Ì??¬?Áa??" FontFamily="KaiTi" FontSize="30" VerticalAlignment="Bottom" HorizontalAlignment="Center"

                      Foreground="#739315" FontWeight="Bold" Margin="0 0 010">

                 <TextBlock.Effect>

                    <DropShadowEffect Color="Yellow" Direction="0"/>

                </TextBlock.Effect>

            </TextBlock>

            <Border Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0 0 0 5">

                <Border.Background>

                    <LinearGradientBrush StartPoint="0 0" EndPoint="1 0">

                        <GradientStop Color="Transparent" Offset="0"/>

                        <GradientStop Color="Black" Offset="0.5"/>

                        <GradientStop Color="Transparent" Offset="1"/>

                    </LinearGradientBrush>

                </Border.Background>

            </Border>

            <ProgressBar x:Name="progressbar01" Height="30" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="1" Background="Transparent"

                        BorderBrush="Black" BorderThickness="1" Maximum="100" Margin="10 5"/>

            <StackPanel Orientation="Horizontal" Grid.Row="2" Margin="10 5">

                <TextBlock Text="¨¬¨°¨®??¨¨:"/>

                <TextBlock Text="{Binding Path=Value,ElementName=progressbar01}" Foreground="Red" Margin="5 0"/>

                <TextBlock Text="%" Foreground="Red"/>

                <TextBlock x:Name="txtb_option" Width="Auto" Margin="20 0 10 0" Foreground="Blue"/>

            </StackPanel>

            <Image Width="60" x:Name="image" Height="60" Margin="10 0" VerticalAlignment="Center" Source="Images/loading.png"

                      RenderTransformOrigin="0.5,0.5" Grid.Row="3"HorizontalAlignment="Left">

                <Image.RenderTransform>

                    <TransformGroup>

                        <ScaleTransform/>

                        <SkewTransform/>

                        <RotateTransform/>

                        <TranslateTransform/>

                    </TransformGroup>

                </Image.RenderTransform>

            </Image>

            <Button Content="¨??Ì??" Height="25" Width="80"HorizontalAlignment="Right" VerticalAlignment="Center"

                   Margin="105" Grid.Row="3" Style="{StaticResourcestyle_button}"/>

          

        </Grid>

    </Border>

 

跳转界面后台逻辑

using System.Threading;

using System.Windows.Media.Animation;

using System.Windows.Threading;

 

namespace WPF_Login_Demo

{

    ///<summary>

    /// Login_Jump.xaml Ì??£¤?-

    ///</summary>

    public partial class Login_Jump : Window

    {

        int i =0;

        //ºyY¨®?线?¨¬

        ThreadThreadLoading;

        //¡ã¬¡§?º?¡¥-

        StoryboardShowStringValue;

        StoryboardHideStringValue;

        StoryboardBeginRound;

        //¡¥ªD

        privatedelegate void SetStatusString(stringstr_status);

        privatedelegate void CancelStatusString();

        //º¦Ì¤y¡¥¡¥ªD

        SetStatusStringsetStatus;

        CancelStatusStringcancelStatus;

        //Ì??¨¦|ä¡ã¬?

        Login_Successsuccess = new Login_Success();

        publicLogin_Jump()

        {

            InitializeComponent();

            ShowStringValue = this.Resources["showStoryBoard"]as Storyboard;

            HideStringValue = this.Resources["hideStoryBoard"]as Storyboard;

            BeginRound = this.Resources["ImageStoryBoard"]as Storyboard;

            setStatus = new SetStatusString(SetStatusValue);

            cancelStatus = new CancelStatusString(CancelStatusValue);

 

            Loaded += newRoutedEventHandler(Login_Jump_Loaded);

            Closed += newEventHandler(Login_Jump_Closed);

        }

 

        void Login_Jump_Closed(object sender, EventArgse)

        {

            success.Show();

        }

 

        voidLogin_Jump_Loaded(object sender, RoutedEventArgs e)

        {

            ThreadLoading = new Thread(Load);

            ThreadLoading.Start();

        }

 

        voidLoad()

        {

            Thread.Sleep(1000);

            this.Dispatcher.Invoke(setStatus,"y¨²?D?º?¡¥¦¨¨?...");

            Thread.Sleep(2000);

            this.Dispatcher.Invoke(cancelStatus);

            this.Dispatcher.Invoke(setStatus,"y¨²?D?¡é¨¦¡è...");

            Thread.Sleep(2000);

            this.Dispatcher.Invoke(cancelStatus);

            this.Dispatcher.Invoke(setStatus,"y¨²?D?tä?º?...");

            Thread.Sleep(3000);

            this.Dispatcher.Invoke(cancelStatus);

            this.Dispatcher.Invoke(setStatus,"y¨²?D???¨?...");

            Thread.Sleep(1000);

            this.Dispatcher.Invoke(cancelStatus);

            this.Dispatcher.Invoke(setStatus,"¦¨¨?¨¦|ê?y¨²¬?Áa...");

            Thread.Sleep(1000);

            this.Dispatcher.Invoke(cancelStatus);

 

 

            this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate(){ Close(); });

        }

 

        voidSetStatusValue(string str_status)

        {

            if(i == 0)

            {

                BeginStoryboard(BeginRound);

                i++;

            }

            this.txtb_option.Text= str_status;

            this.progressbar01.Value+= 20;

            BeginStoryboard(ShowStringValue);

        }

        voidCancelStatusValue()

        {

            BeginStoryboard(HideStringValue);

        }

    }

}

项目源码:

https://files.cnblogs.com/wrl-wuqingxue/WPF_Login_Demo%28WPF%29.zip

posted @ 2013-06-28 13:10  无晴雪  阅读(853)  评论(1编辑  收藏  举报