Lester's WPF\SL Blog

Simple, Easy & Beautiful

Part II : Creating Non-Rectangular Splash Screen - using WPF

Part II : Creating Non-Rectangular Splash Screen - using WPF

  • Comments 5

There was a delay in posting this and guess what - the reason was that the feature was not available in the Jan CTP bits. So I had to wait for the Feb CTP bits to be released. So here is how a simple flash screen could be implemented in WPF.

 

void OnClick(object sender, RoutedEventArgs e)

{

   HwndSourceParameters s = new HwndSourceParameters("visual");

   HwndSourceParameters param = new HwndSourceParameters("vis", 200, 200);

   param.UsesPerPixelOpacity = true;

   

   HwndSource hwndSource = new HwndSource(param);

   using (System.IO.Stream xamlStream = System.IO.File.OpenRead("XamlPad_Saved.xaml"))

   {

      hwndSource.RootVisual = XamlReader.Load(xamlStream) as Visual;

   }

   ShowWindow(hwndSource.Handle, 5);

}

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

Wasnt that simple. The property that was missing in the Jan CTP bits is UsesPerPixelOpacity. Now thats what does the trick. A snapshot of what this looks like is below:

So the flash screen is the moon. If you put in a timer which closes it then you have your initial flashscreen. And for those who were wondering what the xaml that creates the moon looks like, here it goes:

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    <!-- Combines two geometries using the exclude combine mode. -->
    <CombinedGeometry GeometryCombineMode="Exclude">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
 </StackPanel >
 

hmmm... yeah its taken from the SDK ;) ...it has lots of samples and is a good resource to have at hand.

Page 1 of 1 (5 items)