Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Splasher
- {
- private static Window mSplash;
- public static Window SplashScreen
- {
- get
- {
- return mSplash;
- }
- set
- {
- mSplash = value;
- }
- }
- public static void ShowSplashScreen()
- {
- if (mSplash != null)
- {
- try
- {
- mSplash.Show(); // <--- HERE IT THROWS EXCEPTION
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- public static void ShowDialogSplashScreen()
- {
- if (mSplash != null)
- {
- mSplash.ShowDialog();
- }
- }
- public static void CloseSplashScreen()
- {
- if (mSplash != null)
- {
- mSplash.Close();
- if (mSplash is IDisposable)
- {
- (mSplash as IDisposable).Dispose();
- }
- }
- }
- }
- <Window x:Class="My.Tools.XAML.Controls.Windows.WpfSplashScreen"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:My.Tools.XAML.Controls.Windows"
- xmlns:gif="http://wpfanimatedgif.codeplex.com"
- ResizeMode="NoResize" WindowStyle="None"
- WindowStartupLocation="CenterScreen"
- Title="WpfSplashScreen"
- Height="305" Width="585"
- Loaded="Window_Loaded">
- <Window.Background>
- <ImageBrush ImageSource="/My.Tools.XAML;component/Resources/Background.jpg"/>
- </Window.Background>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="0.5*" />
- <RowDefinition Height="2*" />
- <RowDefinition Height="0.5*" />
- </Grid.RowDefinitions>
- <Grid Grid.Row="0">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="50*" />
- <ColumnDefinition Width="50*" />
- </Grid.ColumnDefinitions>
- <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8 5 0 0">
- <Image x:Name="Logo" Width="24" Height="24" VerticalAlignment="Top" />
- <Label x:Name="ScreenTitle" FontFamily="Microsoft Sans Serif" FontSize="11.25" Foreground="White"
- VerticalAlignment="Top" VerticalContentAlignment="Center">ScreenTitle</Label>
- </StackPanel>
- <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" >
- <Label x:Name="MinimizeButton" FontFamily="Webdings" FontSize="18" Foreground="White" HorizontalContentAlignment="Right" MouseLeftButtonUp="MinimizeButton_MouseLeftButtonUp" MouseEnter="MinimizeButton_MouseEnter" MouseLeave="MinimizeButton_MouseLeave">0</Label>
- <Label x:Name="CloseButton" FontFamily="Webdings" FontSize="18" Foreground="White" HorizontalContentAlignment="Right" MouseLeftButtonUp="CloseButton_MouseLeftButtonUp" MouseEnter="CloseButton_MouseEnter" MouseLeave="CloseButton_MouseLeave">r</Label>
- </StackPanel>
- </Grid>
- <StackPanel Grid.Row="1" VerticalAlignment="Center" SnapsToDevicePixels="False" Orientation="Vertical">
- <Label x:Name="Message"
- HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom"
- FontFamily="Microsoft Sans Serif" FontSize="36" FontStyle="Italic" FontWeight="Bold"
- Foreground="White" Content="Message"/>
- <Label x:Name="Submessage"
- Margin="0 0 0 25"
- FontFamily="Microsoft Sans Serif" FontSize="10" Foreground="White"
- HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Top"
- Content="Submessage"/>
- <Image x:Name="img" Stretch="None" HorizontalAlignment="Center"/>
- </StackPanel>
- <StackPanel Grid.Row="2" Orientation="Horizontal">
- <Label x:Name="CurrentTask"
- Margin="8 0 0 3"
- FontFamily="Microsoft Sans Serif" FontSize="18" FontStyle="Italic"
- Foreground="White"
- Content="Loading"
- HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom"/>
- <Label x:Name="Dots"
- Margin="0 0 0 3"
- FontFamily="Microsoft Sans Serif" FontSize="18" FontStyle="Italic"
- Foreground="White"
- HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom">
- <Label.Style>
- <Style TargetType="Label">
- <Style.Triggers>
- <EventTrigger RoutedEvent="Label.Loaded">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Content" Duration="00:00:00.8" RepeatBehavior="Forever">
- <DiscreteObjectKeyFrame KeyTime="00:00:00.0" Value=""/>
- <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="."/>
- <DiscreteObjectKeyFrame KeyTime="00:00:00.4" Value=".."/>
- <DiscreteObjectKeyFrame KeyTime="00:00:00.6" Value="..."/>
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- </Style.Triggers>
- </Style>
- </Label.Style>
- </Label>
- </StackPanel>
- </Grid>
- </Window>
- public partial class WpfSplashScreen : Window
- {
- public WpfSplashScreen()
- {
- InitializeComponent();
- }
- public WpfSplashScreen(string waitMessage, string message, string submessage, string screenTitle, Icon icon)
- : this()
- {
- ImageSource imageSource = icon.ToImageSourceW();
- this.Icon = imageSource;
- this.logo = imageSource;
- this.CurrentTask.Content = waitMessage;
- this.Message.Content = message;
- this.Submessage.Content = submessage;
- this.ScreenTitle.Content = screenTitle;
- this.Logo.Source = logo;
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- var image = new BitmapImage();
- image.BeginInit();
- image.UriSource = new Uri("/My.Tools.XAML;component/Resources/metroProgressBar.gif", UriKind.Relative);
- image.EndInit();
- ImageBehavior.SetAnimatedSource(img, image);
- ImageBehavior.SetAutoStart(img, true);
- ImageBehavior.SetRepeatBehavior(img, RepeatBehavior.Forever);
- }
- // Other stuff
- }
- Splasher.SplashScreen = new WpfSplashScreen("Loading",
- entryAssemblyInfo.ProductTitle,
- string.Format("Version {0}",
- entryAssemblyInfo.Version),
- entryAssemblyInfo.ProductTitle,
- GetWindowIcon());
- Splasher.SplashScreen.Closed += OnSplashScreenClosed;
- Splasher.ShowSplashScreen();
- public static void ShowSplashScreen()
- {
- if (mSplash != null)
- {
- try
- {
- mSplash.Show(); // <--- HERE IT THROWS EXCEPTION
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message); // despite exception is thrown it never reaches here.
- }
- }
- }
Add Comment
Please, Sign In to add comment