Example #1
0
        public static void Show(System.Windows.Controls.UserControl WPFUserControl, string title, string sound, bool topmost, bool isModal)
        {
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            //Create window
            System.Windows.Window wnd = new System.Windows.Window();
            wnd.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);
            wnd.Title = title;

            //Set window style
            try
            {
                wnd.Style = wnd.FindResource("StyleWindowMessage") as Style;
            }
            catch
            {
                //Set default style
                wnd.WindowStyle = WindowStyle.None;
                wnd.AllowsTransparency = true;
                wnd.Background = new SolidColorBrush(Colors.Transparent);
                wnd.ResizeMode = ResizeMode.NoResize;
                wnd.ShowInTaskbar = false;
            }

            object media = wnd.TryFindResource("media");
            if(media != null && media is MediaElement)
            {
                MediaElement mediaElement = media as MediaElement;
                object showSound = wnd.TryFindResource("ShowWindowSound");
                if(showSound != null && showSound is MediaTimeline)
                {
                    mediaElement.LoadedBehavior = MediaState.Manual;
                    mediaElement.UnloadedBehavior = MediaState.Manual;
                    mediaElement.Source = new Uri("pack://application:,,,/SlideWindow;component/show.wav", UriKind.Absolute);//((MediaTimeline)showSound).Source;
                    mediaElement.Volume = 5;
                    mediaElement.Position = new TimeSpan(0);
                }
                mediaElement.Play();
            }

            //Add WPFUserControl to window
            wnd.Content = WPFUserControl;

            //Set parameters
            wnd.Topmost = topmost;

            //Play sound after showing (set delay for sound)

            //Show window
            if(isModal)
                wnd.ShowDialog();
            else
                wnd.Show();

            wnd = null;
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        }