Guest User

Untitled

a guest
Jan 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. public static class Splasher
  2. {
  3. private static Window mSplash;
  4.  
  5. public static Window SplashScreen
  6. {
  7. get
  8. {
  9. return mSplash;
  10. }
  11. set
  12. {
  13. mSplash = value;
  14. }
  15. }
  16.  
  17. public static void ShowSplashScreen()
  18. {
  19. if (mSplash != null)
  20. {
  21. try
  22. {
  23. mSplash.Show(); // <--- HERE IT THROWS EXCEPTION
  24. }
  25. catch (Exception e)
  26. {
  27. Console.WriteLine(e.Message);
  28. }
  29. }
  30. }
  31.  
  32. public static void ShowDialogSplashScreen()
  33. {
  34. if (mSplash != null)
  35. {
  36. mSplash.ShowDialog();
  37. }
  38. }
  39.  
  40. public static void CloseSplashScreen()
  41. {
  42. if (mSplash != null)
  43. {
  44. mSplash.Close();
  45.  
  46. if (mSplash is IDisposable)
  47. {
  48. (mSplash as IDisposable).Dispose();
  49. }
  50. }
  51. }
  52. }
  53.  
  54. <Window x:Class="My.Tools.XAML.Controls.Windows.WpfSplashScreen"
  55. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  56. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  57. xmlns:local="clr-namespace:My.Tools.XAML.Controls.Windows"
  58.  
  59. xmlns:gif="http://wpfanimatedgif.codeplex.com"
  60.  
  61. ResizeMode="NoResize" WindowStyle="None"
  62. WindowStartupLocation="CenterScreen"
  63. Title="WpfSplashScreen"
  64. Height="305" Width="585"
  65. Loaded="Window_Loaded">
  66.  
  67. <Window.Background>
  68. <ImageBrush ImageSource="/My.Tools.XAML;component/Resources/Background.jpg"/>
  69. </Window.Background>
  70. <Grid>
  71. <Grid.RowDefinitions>
  72. <RowDefinition Height="0.5*" />
  73. <RowDefinition Height="2*" />
  74. <RowDefinition Height="0.5*" />
  75. </Grid.RowDefinitions>
  76. <Grid Grid.Row="0">
  77. <Grid.ColumnDefinitions>
  78. <ColumnDefinition Width="50*" />
  79. <ColumnDefinition Width="50*" />
  80. </Grid.ColumnDefinitions>
  81. <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8 5 0 0">
  82. <Image x:Name="Logo" Width="24" Height="24" VerticalAlignment="Top" />
  83. <Label x:Name="ScreenTitle" FontFamily="Microsoft Sans Serif" FontSize="11.25" Foreground="White"
  84. VerticalAlignment="Top" VerticalContentAlignment="Center">ScreenTitle</Label>
  85. </StackPanel>
  86. <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" >
  87. <Label x:Name="MinimizeButton" FontFamily="Webdings" FontSize="18" Foreground="White" HorizontalContentAlignment="Right" MouseLeftButtonUp="MinimizeButton_MouseLeftButtonUp" MouseEnter="MinimizeButton_MouseEnter" MouseLeave="MinimizeButton_MouseLeave">0</Label>
  88. <Label x:Name="CloseButton" FontFamily="Webdings" FontSize="18" Foreground="White" HorizontalContentAlignment="Right" MouseLeftButtonUp="CloseButton_MouseLeftButtonUp" MouseEnter="CloseButton_MouseEnter" MouseLeave="CloseButton_MouseLeave">r</Label>
  89. </StackPanel>
  90. </Grid>
  91. <StackPanel Grid.Row="1" VerticalAlignment="Center" SnapsToDevicePixels="False" Orientation="Vertical">
  92. <Label x:Name="Message"
  93. HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom"
  94. FontFamily="Microsoft Sans Serif" FontSize="36" FontStyle="Italic" FontWeight="Bold"
  95. Foreground="White" Content="Message"/>
  96.  
  97. <Label x:Name="Submessage"
  98. Margin="0 0 0 25"
  99. FontFamily="Microsoft Sans Serif" FontSize="10" Foreground="White"
  100. HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Top"
  101. Content="Submessage"/>
  102.  
  103. <Image x:Name="img" Stretch="None" HorizontalAlignment="Center"/>
  104.  
  105. </StackPanel>
  106. <StackPanel Grid.Row="2" Orientation="Horizontal">
  107. <Label x:Name="CurrentTask"
  108. Margin="8 0 0 3"
  109. FontFamily="Microsoft Sans Serif" FontSize="18" FontStyle="Italic"
  110. Foreground="White"
  111. Content="Loading"
  112. HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom"/>
  113.  
  114. <Label x:Name="Dots"
  115. Margin="0 0 0 3"
  116. FontFamily="Microsoft Sans Serif" FontSize="18" FontStyle="Italic"
  117. Foreground="White"
  118. HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom">
  119. <Label.Style>
  120. <Style TargetType="Label">
  121. <Style.Triggers>
  122. <EventTrigger RoutedEvent="Label.Loaded">
  123. <EventTrigger.Actions>
  124. <BeginStoryboard>
  125. <Storyboard>
  126. <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Content" Duration="00:00:00.8" RepeatBehavior="Forever">
  127. <DiscreteObjectKeyFrame KeyTime="00:00:00.0" Value=""/>
  128. <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="."/>
  129. <DiscreteObjectKeyFrame KeyTime="00:00:00.4" Value=".."/>
  130. <DiscreteObjectKeyFrame KeyTime="00:00:00.6" Value="..."/>
  131. </ObjectAnimationUsingKeyFrames>
  132. </Storyboard>
  133. </BeginStoryboard>
  134. </EventTrigger.Actions>
  135. </EventTrigger>
  136. </Style.Triggers>
  137. </Style>
  138. </Label.Style>
  139. </Label>
  140. </StackPanel>
  141. </Grid>
  142. </Window>
  143.  
  144. public partial class WpfSplashScreen : Window
  145. {
  146. public WpfSplashScreen()
  147. {
  148. InitializeComponent();
  149. }
  150.  
  151. public WpfSplashScreen(string waitMessage, string message, string submessage, string screenTitle, Icon icon)
  152. : this()
  153. {
  154. ImageSource imageSource = icon.ToImageSourceW();
  155. this.Icon = imageSource;
  156. this.logo = imageSource;
  157.  
  158. this.CurrentTask.Content = waitMessage;
  159. this.Message.Content = message;
  160. this.Submessage.Content = submessage;
  161. this.ScreenTitle.Content = screenTitle;
  162. this.Logo.Source = logo;
  163. }
  164.  
  165. private void Window_Loaded(object sender, RoutedEventArgs e)
  166. {
  167. var image = new BitmapImage();
  168. image.BeginInit();
  169. image.UriSource = new Uri("/My.Tools.XAML;component/Resources/metroProgressBar.gif", UriKind.Relative);
  170. image.EndInit();
  171. ImageBehavior.SetAnimatedSource(img, image);
  172.  
  173. ImageBehavior.SetAutoStart(img, true);
  174. ImageBehavior.SetRepeatBehavior(img, RepeatBehavior.Forever);
  175. }
  176.  
  177. // Other stuff
  178. }
  179.  
  180. Splasher.SplashScreen = new WpfSplashScreen("Loading",
  181. entryAssemblyInfo.ProductTitle,
  182. string.Format("Version {0}",
  183. entryAssemblyInfo.Version),
  184. entryAssemblyInfo.ProductTitle,
  185. GetWindowIcon());
  186.  
  187. Splasher.SplashScreen.Closed += OnSplashScreenClosed;
  188. Splasher.ShowSplashScreen();
  189.  
  190. public static void ShowSplashScreen()
  191. {
  192. if (mSplash != null)
  193. {
  194. try
  195. {
  196. mSplash.Show(); // <--- HERE IT THROWS EXCEPTION
  197. }
  198. catch (Exception e)
  199. {
  200. Console.WriteLine(e.Message); // despite exception is thrown it never reaches here.
  201. }
  202. }
  203. }
Add Comment
Please, Sign In to add comment