WPF登录提示窗体实现原理
![](http://images0.cnblogs.com/blog/540289/201306/28130820-2766bfe2835445728dd1aacf2038c65f.png)
<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;
//数ºy据Y加¨®载?线?程¨¬
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