コード例 #1
0
        public void Create <TViewModel>(ViewModelBase ownerViewModel = null, bool isDialog = false) where TViewModel : ViewModelBase, new()
        {
            var viewModel = new TViewModel();

            var window = new DefaultWindow
            {
                DataContext           = viewModel,
                SizeToContent         = SizeToContent.WidthAndHeight,
                Owner                 = GetViewByViewModel(ownerViewModel),
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
            };

            if (ownerViewModel == null)
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            window.Loaded  += viewModel.OnLoaded;
            window.Closing += viewModel.OnClosing;

            Application.Current.Dispatcher.Invoke(() =>
            {
                if (!isDialog)
                {
                    window.Show();
                }
                else
                {
                    window.ShowDialog();
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Windowを生成して返す
        /// </summary>
        /// <returns></returns>
        protected virtual Window CreateWindow(INotification notification)
        {
            Window window;

            if (this.WindowType == null)
            {
                if (notification == null)
                {
                    window = new DefaultWindow()
                    {
                        Width = 300, Height = 150
                    };
                }
                else if (notification is IConfirmation)
                {
                    window = new DefaultConfirmationWindow()
                    {
                        Confirmation = (IConfirmation)notification
                    };
                }
                else
                {
                    window = new DefaultNotificationWindow()
                    {
                        Notification = notification
                    };
                }
            }
            else
            {
                window = this.WindowType.GetConstructor(Type.EmptyTypes).Invoke(null) as Window;
            }
            return(window);
        }
コード例 #3
0
        public void Load(IBootContext b)
        {
            if (b.Contains("LocalizeBootloader"))
            {
                b.Requeue();
                return;
            }


            MainWindow = new DefaultWindow()
            {
                //WindowStartupLocation = WindowStartupLocation.CenterScreen,
                //WindowState =  WindowState.Maximized
            };

            MainWindow.Closing += (sender, args) => System.Windows.Application.Current.Shutdown();
            MainWindow.Show();

            _info.Version = Assembly.GetCallingAssembly().GetName().Version;

            InitializeCultures();

            if (Updater != null)
            {
                Updater.CheckVersion();

                if (Updater.NewVersionFound)
                {
                    var updaterView = new ApplicationUpdateView
                    {
                        DataContext = Updater
                    };
                    // TODO : updaterView.ShowDialog();

                    if (Updater.Updated)
                    {
                        System.Windows.Application.Current.Shutdown();
                        return;;
                    }
                }
            }


            ViewModel = _getVm();
            var w = _mvvm.MainContext.GetView(ViewModel, MainViewMode);


            _menu.RegisterMenu("file", "{File}", null, null);
            _menu.RegisterMenu("data", "{Data}", null, null);
            _menu.RegisterMenu("param", "{Parameters}", null, null);
            _menu.RegisterMenu("tools", "{Tools}", null, null);
            _menu.RegisterMenu("help", "{_?}", null, null);


            _menu.RegisterMenu("file/exit", "{Exit}", ViewModel.Exit, null);

            MainWindow.Content = w;

            return;
        }
コード例 #4
0
        /// <summary>
        /// When no WindowContent is sent this method is used to create a default basic window to show
        /// the corresponding <see cref="INotification"/> or <see cref="IConfirmation"/>.
        /// </summary>
        /// <param name="notification">The INotification or IConfirmation parameter to show.</param>
        /// <returns></returns>
        protected MetroWindow CreateDefaultWindow(INotification notification)
        {
            MetroWindow window = null;

            if (notification is INormalNotification)
            {
                window = new DefaultWindow()
                {
                    Notification = notification
                };
            }
            else if (notification is IConfirmation)
            {
                window = new DefaultConfirmationWindow()
                {
                    Confirmation = (IConfirmation)notification
                };
            }
            else
            {
                var findItem = PopupWindows.CurrentWidows.Find(o => o.Uid == notification.Id);
                if (findItem != null)
                {
                    window = findItem;
                }
                else
                {
                    notification.Id = notification.Id ?? Guid.NewGuid().ToString();
                    window          = new DefaultNotificationWindow()
                    {
                        Notification = notification
                    };
                    window.Uid = notification.Id;
                }

                //notification.Id = notification.Id ?? Guid.NewGuid().ToString();
                //window = new DefaultNotificationWindow() { Notification = notification };
                //window.Uid = notification.Id;
            }

            var mainWindow = Application.Current.MainWindow;

            window.Uid = notification.Id;
            // notification.SecOwner = window;
            if (notification.SecondOwner)
            {
                // window.Owner = notification.SecOwner;
            }
            else
            {
                window.Owner = mainWindow;
            }

            PopupWindows.CurrentWidows.Add(window);

            //  PopupWindows.CurrentWidows.Add(window);

            return(window);
        }
コード例 #5
0
        /// <summary>
        /// Gets the scale for the current display.
        /// </summary>
        /// <remarks>
        /// Consider using the <see cref="CompositionTarget.TransformToDevice"/> matrix, provided by <see cref="PresentationSource.CompositionTarget"/> instead.
        /// </remarks>
        /// <param name="window">Window.</param>
        /// <param name="defaultWindow">Determines the function's return value if the window does not intersect any display monitor.</param>
        /// <returns>The device scale factor.</returns>
        /// <seealso cref="TryGetDpiForCurrentMonitor(Window, DefaultWindow, out Interop.DpiScale)"/>
        public static double?GetScaleFactorForCurrentMonitor(this Window window, DefaultWindow defaultWindow)
        {
            IntPtr monitorHandle = NativeMethods.MonitorFromWindow(window.GetHandle(), defaultWindow);
            int    scaleFactor   = 1;

            _ = NativeMethods.GetScaleFactorForMonitor(monitorHandle, ref scaleFactor);
            return(scaleFactor / 100d);
        }
コード例 #6
0
ファイル: Tests.xaml.cs プロジェクト: ArmRob1/Toefl_TPO
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DefaultWindow dw   = new DefaultWindow();
            Edit          edit = new Edit();

            dw.Content = edit.Content;
            dw.Title   = edit.Title;
            dw.Owner   = Window.GetWindow(this);
            dw.Show();
        }
コード例 #7
0
 private void _setOpenValue(DefaultWindow menu, bool value)
 {
     _gameHud.CharacterButtonDown = value;
     if (value)
     {
         menu.OpenCentered();
     }
     else
     {
         menu.Close();
     }
 }
コード例 #8
0
        public static bool TryGetDisplayInfo(this Window window, DefaultWindow defaultWindow, [System.Diagnostics.CodeAnalysis.MaybeNullWhen(true)] out DisplayDevice displayDevice)
#endif
        {
            displayDevice = default;
            if (window.TryGetMonitorInfo(defaultWindow, out MonitorInfo monitorInfo))
            {
                displayDevice.Init();
                return(NativeMethods.EnumDisplayDevices(monitorInfo.DeviceName, 0, ref displayDevice, 1));
            }

            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Gets the DPI for the current display.
        /// </summary>
        /// <remarks>
        /// Consider using the <see cref="CompositionTarget.TransformToDevice"/> matrix, provided by <see cref="PresentationSource.CompositionTarget"/> instead.
        /// </remarks>
        /// <param name="window">Window.</param>
        /// <param name="defaultWindow">Determines the function's return value if the window does not intersect any display monitor.</param>
        /// <param name="dpiScale">The dpi scale for the current monitor.</param>
        /// <returns>True if the function succeeded.</returns>
        public static bool TryGetDpiForCurrentMonitor(this Window window, DefaultWindow defaultWindow, out Interop.DpiScale dpiScale)
        {
            IntPtr hMonitor = NativeMethods.MonitorFromWindow(window.GetHandle(), defaultWindow);

            if (hMonitor != IntPtr.Zero && NativeMethods.GetDpiForMonitor(hMonitor, MonitorDpiType.MDT_EFFECTIVE_DPI, out dpiScale) == 0)
            {
                return(true);
            }

            dpiScale = default;
            return(false);
        }
コード例 #10
0
        /// <summary>
        /// Returns the window to display as part of the trigger action.
        /// </summary>
        /// <param name="notification">The notification to be set as a DataContext in the window.</param>
        /// <returns></returns>
        protected virtual Window GetWindow(INotification notification)
        {
            Window wrapperWindow;

            if (this.WindowContent != null || this.WindowContentType != null)
            {
                wrapperWindow = new DefaultWindow()
                {
                    Notification = notification
                };

                if (wrapperWindow == null)
                {
                    throw new NullReferenceException("CreateWindow cannot return null");
                }

                // If the WindowContent does not have its own DataContext, it will inherit this one.
                wrapperWindow.DataContext = notification;
                wrapperWindow.Title       = notification.Title;

                this.PrepareContentForWindow(notification, wrapperWindow);
            }
            else
            {
                wrapperWindow = this.CreateDefaultWindow(notification);
            }

            if (AssociatedObject != null)
            {
                wrapperWindow.Owner = notification.HasOwner ? Window.GetWindow(AssociatedObject):null;
            }
            //wrapperWindow.WindowState = IsMaximized ? WindowState.Maximized : WindowState.Normal;
            // If the user provided a Style for a Window we set it as the window's style.
            IsModal = notification.IsModal;
            if (WindowStyle != null)
            {
                wrapperWindow.Style = WindowStyle;
            }

            // If the user has provided a startup location for a Window we set it as the window's startup location.
            if (WindowStartupLocation.HasValue)
            {
                wrapperWindow.WindowStartupLocation = WindowStartupLocation.Value;
            }

            if (wrapperWindow == null)
            {
                throw new NullReferenceException("CreateWindow cannot return null");
            }

            return(wrapperWindow);
        }
コード例 #11
0
        public static bool TryGetMonitorInfo(this Window window, DefaultWindow defaultWindow, [System.Diagnostics.CodeAnalysis.MaybeNullWhen(true)] out MonitorInfo monitorInfo)
#endif
        {
            monitorInfo = default;
            IntPtr monitorHandle = NativeMethods.MonitorFromWindow(window.GetHandle(), defaultWindow);

            if (monitorHandle == IntPtr.Zero)
            {
                return(false);
            }

            monitorInfo.Init(); // This MUST be invoked.
            return(NativeMethods.GetMonitorInfo(monitorHandle, ref monitorInfo));
        }
コード例 #12
0
        public override async void Initialize(DefaultWindow window, ViewVariablesBlobMetadata blob, ViewVariablesRemoteSession session)
        {
            // TODO: this is pretty poorly implemented right now.
            // For example, it assumes a client-side entity exists,
            // so it also means client bubbling won't work in this context.

            _entitySession = session;

            _membersBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(session, new ViewVariablesRequestMembers());

            var uid = (EntityUid)_membersBlob.MemberGroups.SelectMany(p => p.Item2).Single(p => p.Name == "Uid").Value;

            Initialize(window, uid);
        }
コード例 #13
0
        public static Window AsWindow(this FrameworkElement view)
        {
            if (view is Window win)
            {
                return(win);
            }

            var w = new DefaultWindow
            {
                DataContext = view?.DataContext,
                View        = view,
                //SizeToContent = SizeToContent.WidthAndHeight,
                //WindowStartupLocation = WindowStartupLocation.CenterOwner,
            };

            return(w);
        }
コード例 #14
0
ファイル: ProjectEditPage.xaml.cs プロジェクト: AProgy/TOEFL
        private void fill_Click(object sender, RoutedEventArgs e)
        {
            DefaultWindow    dw  = new DefaultWindow();
            QuestionEditPage qep = new QuestionEditPage();

            dw.Icon = BitmapFrame.Create(System.Windows.Application.GetResourceStream
                                             (new Uri(@"Images\edit.png", UriKind.RelativeOrAbsolute)).Stream);

            dw.MinHeight = qep.MinHeight;
            dw.MinWidth  = qep.MinWidth;
            dw.Content   = qep.Content;
            dw.Title     = qep.Title;

            dw.Height = 500;
            dw.Width  = 900;

            dw.ShowDialog();
        }
コード例 #15
0
        private void NewTest_Click(object sender, RoutedEventArgs e)
        {
            DefaultWindow  dw  = new DefaultWindow();
            NewProjectPage npp = new NewProjectPage();

            dw.Icon = BitmapFrame.Create(Application.GetResourceStream
                                             (new Uri(@"Images\edit.png", UriKind.RelativeOrAbsolute)).Stream);

            dw.MinHeight = npp.MinHeight;
            dw.MinWidth  = npp.MinWidth;
            dw.Content   = npp.Content;
            dw.Title     = npp.Title;

            dw.Height = 400;
            dw.Width  = 400;

            dw.ShowDialog();
        }
コード例 #16
0
        public static Window AsDialog(this FrameworkElement view)
        {
            if (view is Window win)
            {
                return(win);
            }

            var w = new DefaultWindow
            {
                DataContext = view?.DataContext,
                View        = view,

                SizeToContent         = SizeToContent.WidthAndHeight,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                WindowStyle           = WindowStyle.None,
                ResizeMode            = ResizeMode.NoResize,
            };

            return(w);
        }
コード例 #17
0
ファイル: NewProjectPage.xaml.cs プロジェクト: AProgy/TOEFL
        private void Next_Click(object sender, RoutedEventArgs e)
        {
            // TODO
            string file = Tools.CreateNewProject(projectName.Text);
            //add in project's list

            DefaultWindow   dw  = new DefaultWindow();
            ProjectEditPage pep = new ProjectEditPage(projectName.Text, file, dw);


            dw.Icon = BitmapFrame.Create(Application.GetResourceStream
                                             (new Uri(@"Images\edit.png", UriKind.RelativeOrAbsolute)).Stream);

            dw.MinHeight = pep.MinHeight;
            dw.MinWidth  = pep.MinWidth;
            dw.Content   = pep.Content;
            dw.Title     = pep.Title;

            Window.GetWindow(sender as Button).Close();
            dw.ShowDialog();
        }
コード例 #18
0
ファイル: ProjectEditPage.xaml.cs プロジェクト: AProgy/TOEFL
        public ProjectEditPage(string projectName, string filePath, DefaultWindow dw)
        {
            InitializeComponent();
            ProjectName             = projectName;
            this.projectName.Header = ProjectName;
            FilePath   = filePath;
            ThisWindow = dw;
            Tools.AddReadingFile(FilePath);

            texts = new List <string>()
            {
                "adas",
                "das",
                "xdas",
                "cdas",
                "vdas",
                "bdas",
            };

            listBox.ItemsSource = texts;
        }
コード例 #19
0
ファイル: NotifyIconVM.cs プロジェクト: Yxx-yym/ProjectEvent
        private MainViewModel CreateMainWindow(string uri)
        {
            var mainWindow  = serviceProvider.GetService <MainWindow>();
            var dataContext = serviceProvider.GetService <MainViewModel>();

            mainWindow.DataContext = dataContext;
            dataContext.SelectGroup(-1);
            dataContext.Uri    = nameof(IndexPage);
            mainWindow.Closed += MainWindow_Closed;
            mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            mainWindow.Show();
            mainWindow.Activate();
            isMainWindowShow = true;
            this.mainWindow  = mainWindow;

            if (uri != nameof(IndexPage))
            {
                dataContext.Uri = uri;
            }
            return(dataContext);
        }
コード例 #20
0
 /// <summary>
 ///     Initializes this instance to work on a remote object.
 ///     This is called when the view variables manager has already made a session to the remote object.
 /// </summary>
 /// <param name="window">The window to initialize by adding GUI components.</param>
 /// <param name="blob">The data blob sent by the server for this remote object.</param>
 /// <param name="session">The session connecting to the remote object.</param>
 public virtual void Initialize(DefaultWindow window, ViewVariablesBlobMetadata blob, ViewVariablesRemoteSession session)
 {
     throw new NotSupportedException();
 }
コード例 #21
0
 /// <summary>
 ///     Initializes this instance to work on a local object.
 /// </summary>
 /// <param name="window">The window to initialize by adding GUI components.</param>
 /// <param name="obj">The object that is being VV'd</param>
 public abstract void Initialize(DefaultWindow window, object obj);
コード例 #22
0
        public override void Initialize(DefaultWindow window, object obj)
        {
            _entity = (EntityUid)obj;

            var scrollContainer = new ScrollContainer();

            //scrollContainer.SetAnchorPreset(Control.LayoutPreset.Wide, true);
            window.Contents.AddChild(scrollContainer);
            var vBoxContainer = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical
            };

            scrollContainer.AddChild(vBoxContainer);

            // Handle top bar displaying type and ToString().
            {
                Control top;
                var     stringified = PrettyPrint.PrintUserFacingWithType(obj, out var typeStringified);
                if (typeStringified != "")
                {
                    //var smallFont = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/CALIBRI.TTF"), 10);
                    // Custom ToString() implementation.
                    var headBox = new BoxContainer
                    {
                        Orientation        = LayoutOrientation.Vertical,
                        SeparationOverride = 0
                    };
                    headBox.AddChild(new Label {
                        Text = stringified, ClipText = true
                    });
                    headBox.AddChild(new Label
                    {
                        Text = typeStringified,
                        //    FontOverride = smallFont,
                        FontColorOverride = Color.DarkGray,
                        ClipText          = true
                    });
                    top = headBox;
                }
                else
                {
                    top = new Label {
                        Text = stringified
                    };
                }

                if (_entityManager.TryGetComponent(_entity, out ISpriteComponent? sprite))
                {
                    var hBox = new BoxContainer
                    {
                        Orientation = LayoutOrientation.Horizontal
                    };
                    top.HorizontalExpand = true;
                    hBox.AddChild(top);
                    hBox.AddChild(new SpriteView {
                        Sprite = sprite, OverrideDirection = Direction.South
                    });
                    vBoxContainer.AddChild(hBox);
                }
                else
                {
                    vBoxContainer.AddChild(top);
                }
            }

            _tabs = new TabContainer();
            _tabs.OnTabChanged += _tabsOnTabChanged;
            vBoxContainer.AddChild(_tabs);

            var clientVBox = new BoxContainer
            {
                Orientation        = LayoutOrientation.Vertical,
                SeparationOverride = 0
            };

            _tabs.AddChild(clientVBox);
            _tabs.SetTabTitle(TabClientVars, Loc.GetString("view-variable-instance-entity-client-variables-tab-title"));

            var first = true;

            foreach (var group in LocalPropertyList(obj, ViewVariablesManager, _robustSerializer))
            {
                ViewVariablesTraitMembers.CreateMemberGroupHeader(
                    ref first,
                    TypeAbbreviation.Abbreviate(group.Key),
                    clientVBox);

                foreach (var control in group)
                {
                    clientVBox.AddChild(control);
                }
            }

            _clientComponents = new BoxContainer
            {
                Orientation        = LayoutOrientation.Vertical,
                SeparationOverride = 0
            };
            _tabs.AddChild(_clientComponents);
            _tabs.SetTabTitle(TabClientComponents, Loc.GetString("view-variable-instance-entity-client-components-tab-title"));

            PopulateClientComponents();

            if (!_entity.IsClientSide())
            {
                _serverVariables = new BoxContainer
                {
                    Orientation        = LayoutOrientation.Vertical,
                    SeparationOverride = 0
                };
                _tabs.AddChild(_serverVariables);
                _tabs.SetTabTitle(TabServerVars, Loc.GetString("view-variable-instance-entity-server-variables-tab-title"));

                _serverComponents = new BoxContainer
                {
                    Orientation        = LayoutOrientation.Vertical,
                    SeparationOverride = 0
                };
                _tabs.AddChild(_serverComponents);
                _tabs.SetTabTitle(TabServerComponents, Loc.GetString("view-variable-instance-entity-server-components-tab-title"));

                PopulateServerComponents(false);
            }
        }
コード例 #23
0
        /// <summary>
        /// Obtain information on a display monitor associated with this window.
        /// </summary>
        /// <param name="window">Window of interest.</param>
        /// <param name="defaultWindow">Determines the function's return value if the window does not intersect any display monitor.</param>
        /// <param name="displayDevice">Display information for selected display.</param>
        /// <returns>Information about the display device.</returns>
        /// <exception cref="COMException">Win32 error.</exception>
#if NET451
        public static bool TryGetDisplayInfo(this Window window, DefaultWindow defaultWindow, out DisplayDevice displayDevice)
コード例 #24
0
        /// <summary>
        /// Retrieve information about the display monitor for this window.
        /// </summary>
        /// <param name="window">Window of interest.</param>
        /// <param name="defaultWindow">Determines the function's return value if the window does not intersect any display monitor.</param>
        /// <param name="monitorInfo">Result. Empty when the method returns false.</param>
        /// <returns>Monitor info for the specified window.</returns>
#if NET451
        public static bool TryGetMonitorInfo(this Window window, DefaultWindow defaultWindow, out MonitorInfo monitorInfo)
コード例 #25
0
 public static extern IntPtr MonitorFromWindow(IntPtr hwnd, DefaultWindow dwFlags);
コード例 #26
0
ファイル: NotifyIconVM.cs プロジェクト: Yxx-yym/ProjectEvent
 private void MainWindow_Closed(object sender, EventArgs e)
 {
     isMainWindowShow = false;
     this.mainWindow  = null;
 }