Exemplo n.º 1
0
        private TWindow ShowWindow <TWindow>()
            where TWindow : Window, new()
        {
            TWindow form = new TWindow();

            form.Show();
            return(form);
        }
Exemplo n.º 2
0
        protected static void Navigate <TWindow, TViewModel>()
            where TWindow : Window, new()
            where TViewModel : class
        {
            TWindow w = new TWindow();

            w.Show();
            TViewModel vm = Activator.CreateInstance(typeof(TViewModel)) as TViewModel;

            w.DataContext = vm;
        }
        public static void ShowAsActive(this TWindow window)
        {
            window.ShowActivated = true;
            window.Topmost       = true;

            window.Show();
            Screen s = Screen.FromPoint(Cursor.Position);

            window.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
            window.Left           = s.WorkingArea.Right / HIOStaticValues.scale - window.Width - 16;
            window.Top            = (s.WorkingArea.Top / HIOStaticValues.scale) + 60;
            HIOStaticValues.scale = PresentationSource.FromVisual(window).CompositionTarget.TransformToDevice.M11;
            window.Activate();
            window.Focus();
        }
Exemplo n.º 4
0
        public static void ShowOrActivate <TWindow>()
            where TWindow : Window, new()
        {
            // 対象Windowが開かれているか探す
            var window = Application.Current.Windows.OfType <TWindow>().FirstOrDefault();

            if (window == null)
            {
                // 開かれてなかったら開く
                window = new TWindow();
                window.Show();
            }
            else
            {
                // 既に開かれていたらアクティブにする
                window.Activate();
            }
        }
    public static void CreateWindow <TWindow>()
        where TWindow : Window, new()
    {
        // Create a thread
        Thread newWindowThread = new Thread(new ThreadStart(() =>
        {
            SynchronizationContext.SetSynchronizationContext(
                new DispatcherSynchronizationContext(
                    Dispatcher.CurrentDispatcher));
            TWindow tempWindow = new TWindow();
            tempWindow.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
            tempWindow.Show();
            System.Windows.Threading.Dispatcher.Run();
        }));

        newWindowThread.SetApartmentState(ApartmentState.STA);
        newWindowThread.IsBackground = true;
        newWindowThread.Start();
    }
Exemplo n.º 6
0
        private Task RunNewWindowAsync <TWindow>() where TWindow : System.Windows.Window, new()
        {
            TaskCompletionSource <object> tc = new TaskCompletionSource <object>();
            Thread thread = new Thread(() =>
            {
                TWindow win = new TWindow();
                win.Closed += (d, k) =>
                {
                    System.Windows.Threading.Dispatcher.ExitAllFrames();
                };
                win.Show();
                System.Windows.Threading.Dispatcher.Run();
                tc.SetResult(null);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return(tc.Task);
        }