Esempio n. 1
0
        private void LaunchDialog(Window mainWindow, IContentDialogBase content, bool showDialog)
        {
            if (content.IsUnique && !content.IsClosed && this.dialogs.TryGetValue(content, out var dialog))
            {
                dialog.Activate();
                return;
            }

            var dialogModel = this.container.Resolve <DialogHostViewModel>();

            dialog = new DialogHost {
                DataContext = dialogModel, Owner = mainWindow
            };
            dialogModel.Content = content;
            content.Closed     += (o, e) => dialog.Close();
            dialogModel.Closed += (o, e) => dialog.Close();

            if (content.IsUnique)
            {
                this.dialogs[content] = dialog;
            }

            if (showDialog)
            {
                dialog.ShowDialog();
            }
            else
            {
                dialog.Show();
            }
        }
Esempio n. 2
0
        private void LaunchDialog(Window mainWindow, IContentDialogBase content)
        {
            var dialogModel = this.container.Resolve <DialogHostViewModel>();
            var dialog      = new DialogHost {
                DataContext = dialogModel, Owner = mainWindow
            };

            dialogModel.Content = content;
            content.Closed     += (o, e) => dialog.Close();
            dialogModel.Closed += (o, e) => dialog.Close();
            dialog.ShowDialog();
        }
Esempio n. 3
0
        private async void LoadingView_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_url == null)
                {
                    throw new NullReferenceException(nameof(_url));
                }
                var videos = await VideoService.GetVideosAsync(_url);

                IReadOnlyList <VideoDownloadOption>?videoOptions;
                string?title = default;

                if (videos.Length == 1)
                {
                    videoOptions = await VideoService.GetVideoDownloadOptionsAsync(_url);
                }
                else
                {
                    videoOptions = YoutubeVideoService.GetOptionPlaylist().Reverse().ToArray();
                    title        = await VideoService.GetPlaylistTitle(_url);
                }

                DialogHost.Close("MainDialog", new YoutubeVideoModel(videos, videoOptions, title));
            }
            catch (Exception)
            {
                DialogHost.Close("MainDialog");
            }
        }
Esempio n. 4
0
        public void WhenClosingDialogWithInvalidIdentifierItThrowsWhenNoMatchingInstances()
        {
            object id = Guid.NewGuid();
            var    ex = Assert.Throws <InvalidOperationException>(() => DialogHost.Close(id));

            Assert.Equal($"No loaded DialogHost have an Identifier property matching dialogIdentifier ('{id}') argument.", ex.Message);
        }
Esempio n. 5
0
 protected virtual void OkExecute()
 {
     UpdateFlag = true;
     RaisePropertyChanged(nameof(UpdateFlag));
     Action();
     DialogHost.Close();
 }
        public override void SubscribeMessenger()
        {
            //非阻塞式窗口提示消息
            Messenger.Default.Register <string>(view, "Snackbar", arg =>
            {
                var messageQueue = view.SnackbarThree.MessageQueue;
                messageQueue.Enqueue(arg);
            });
            //阻塞式窗口提示消息
            Messenger.Default.Register <MsgInfo>(view, "UpdateDialog", m =>
            {
                if (m.IsOpen)
                {
                    _ = DialogHost.Show(new SplashScreenView()
                    {
                        DataContext = new { Msg = m.Msg }
                    }, "Root");
                }
                else
                {
                    DialogHost.Close("Root");
                }
            });
            //最小化
            Messenger.Default.Register <string>(view, "WindowMinimize", arg =>
            {
                view.WindowState = System.Windows.WindowState.Minimized;
            });
            //最大化
            Messenger.Default.Register <string>(view, "WindowMaximize", arg =>
            {
                if (view.WindowState == System.Windows.WindowState.Maximized)
                {
                    view.WindowState = System.Windows.WindowState.Normal;
                }
                else
                {
                    view.WindowState = System.Windows.WindowState.Maximized;
                }
            });
            //菜单执行相关动画及模板切换
            Messenger.Default.Register <string>(view, "ExpandMenu", arg =>
            {
                if (view.MENU.Width < 200)
                {
                    AnimationHelper.CreateWidthChangedAnimation(view.MENU, 60, 200, new TimeSpan(0, 0, 0, 0, 300));
                }
                else
                {
                    AnimationHelper.CreateWidthChangedAnimation(view.MENU, 200, 60, new TimeSpan(0, 0, 0, 0, 300));
                }

                //由于...
                var template = view.IC.ItemTemplateSelector;
                view.IC.ItemTemplateSelector = null;
                view.IC.ItemTemplateSelector = template;
            });
            base.SubscribeMessenger();
        }
Esempio n. 7
0
        public void WhenClosingDialogItThrowsWhenNoInstancesLoaded()
        {
            _dialogHost.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));

            var ex = Assert.Throws <InvalidOperationException>(() => DialogHost.Close(null));

            Assert.Equal("No loaded DialogHost instances.", ex.Message);
        }
        protected virtual void Save(object value)
        {
            DialogParameters param = new DialogParameters();

            param.Add("Value", value);

            DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK, param));
        }
Esempio n. 9
0
 private void Save()
 {
     HotKeySettingsManager.Instance.RegisterGlobalHotKey(new HotKeyModel()
     {
         SelectType = SelectType,
         SelectKey  = SelectKey
     });
     DialogHost.Close(IdentifierName);
 }
Esempio n. 10
0
        private void SetClass_Click(object sender, RoutedEventArgs e)
        {
            if (_characterClass != null)
            {
                var mainModel = App.ServiceProvider.GetRequiredService <MainWindowViewModel>();
                mainModel.CharacterLevels[_level - 1].Class = _characterClass;
                mainModel.UpdateCharacterLevels();
            }

            DialogHost.Close("Main");
        }
Esempio n. 11
0
 public void Loding_close()
 {
     try
     {
         DialogHost.Close("ReadDialog");
     }
     catch (Exception ex)
     {
         MessageTips(ex.Message);
     }
 }
        private async void Window_Initialized(object sender, EventArgs e)
        {
            RemoveModWindow = new RemoveModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            EditModWindow = new EditModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            SettingsWindow = new SettingsWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            var mods = Shrek2MM.LoadMods();

            if (mods == null)
            {
                MessageBox.Show("Failed to load Added Mods correctly, this might indicate that the JSON file is corrupted or damaged! Please close this application and ensure the JSON file isn't damaged in any way before proceeding.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            var extractedModLoader = await Shrek2MM.ExtractModLoader();

            if (extractedModLoader == false)
            {
                MessageBox.Show("Couldn't extract the Mod Loader which is embedded in the Shrek 2 Mod Manager Program. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            mods.ForEach(mod => ModItems.Add(mod));

            ModItemsList.ItemsSource = ModItems;
        }
Esempio n. 13
0
        public void login()
        {
            if (userNameBox.Text == null || userNameBox.Text == "")
            {
                MessageTips("请输入Username用户名");
                return;
            }
            else if (passWordBox.Password == null || passWordBox.Password == "")
            {
                MessageTips("请输入Password密码");
                return;
            }
            //else if (nameBox.Text == null || nameBox.Text == "")
            //{
            //    MessageTips("请先刷卡认证您的资料");
            //    return;
            //}
            LogindTips();
            string username = userNameBox.Text;
            string password = passWordBox.Password;
            bool?  isRember = CheckBox_isRember.IsChecked;

            Task.Run(() =>
            {
                Thread.Sleep(500);//看效果
                ResultJson <LoginModel> dictionaries = LoginService.Login_Ex(username, password, isRember);
                this.Dispatcher.Invoke(() =>
                {
                    DialogHost.Close("LoginDialog");
                    if (dictionaries.code == "20000")
                    {
                        CommonHelper.userName      = userNameBox.Text.Trim() ?? "";
                        CommonHelper.passWord      = passWordBox.Password.Trim() ?? "";
                        CommonHelper.detectionName = dictionaries.data.principal ?? "";
                        CommonHelper.jcdName       = dictionaries.data.jcdName ?? "";
                        CommonHelper.districtName  = dictionaries.data.districtName ?? "";
                        CommonHelper.xzjdName      = dictionaries.data.xzjdName ?? "";
                        CommonHelper.cydName       = dictionaries.data.cydName ?? "";
                        index = new Index(CommonHelper.detectionName);
                        index.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageTips(dictionaries.message);
                    }
                });
            });
        }
Esempio n. 14
0
        public void WhenOpenDialogsAreOpenIsExist()
        {
            object id = Guid.NewGuid();

            _dialogHost.Identifier = id;
            bool isExist = false;

            _ = _dialogHost.ShowDialog("Content", new DialogOpenedEventHandler((sender, arg) =>
            {
                isExist = DialogHost.IsDialogOpen(id);
            }));
            Assert.True(isExist);
            DialogHost.Close(id);
            Assert.False(DialogHost.IsDialogOpen(id));
        }
Esempio n. 15
0
        public void WhenClosingDialogWithMultipleDialogHostsItThrowsTooManyMatchingInstances()
        {
            var secondInstance = new DialogHost();

            try
            {
                secondInstance.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
                var ex = Assert.Throws <InvalidOperationException>(() => DialogHost.Close(null));
                Assert.Equal("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern.", ex.Message);
            }
            finally
            {
                secondInstance.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));
            }
        }
Esempio n. 16
0
 private void ApplyArchetype_Click(object sender, RoutedEventArgs e)
 {
     if (_archetype != null)
     {
         try
         {
             (DataContext as ArchetypeSelectorDialogViewModel).Class.AddArchetype(_archetype);
             App.ServiceProvider.GetRequiredService <MainWindowViewModel>().UpdateCharacterLevels();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     DialogHost.Close("Main");
 }
Esempio n. 17
0
        public void WhenClosingDialogWithParameterItPassesParameterToHandlers()
        {
            object parameter        = Guid.NewGuid();
            object closingParameter = null;

            _dialogHost.DialogClosing += DialogClosing;
            _dialogHost.IsOpen         = true;

            DialogHost.Close(null, parameter);

            Assert.Equal(parameter, closingParameter);

            void DialogClosing(object sender, DialogClosingEventArgs eventArgs)
            {
                closingParameter = eventArgs.Parameter;
            }
        }
Esempio n. 18
0
 private static async void DisplayDialog(string msg)
 {
     if (!DialogHost.IsDialogOpen("MainDialogHost"))
     {
         SystemSounds.Exclamation.Play();
         ErrorDialog error = new();
         error.Message = msg;
         _             = await DialogHost.Show(error, "MainDialogHost");
     }
     else
     {
         DialogHost.Close("MainDialogHost");
         SystemSounds.Exclamation.Play();
         ErrorDialog error = new();
         error.Message = msg;
         _             = await DialogHost.Show(error, "MainDialogHost");
     }
 }
Esempio n. 19
0
        public override void SubscribeMessenger()
        {
            //非阻塞式窗口提示消息
            WeakReferenceMessenger.Default.Register <string, string>(view, "Snackbar", (sender, arg) =>
            {
                var messageQueue = view.SnackbarThree.MessageQueue;
                messageQueue.Enqueue(arg);
            });
            //阻塞式窗口提示消息
            WeakReferenceMessenger.Default.Register <MsgInfo, string>(view, "UpdateDialog", (sender, m) =>
            {
                if (m.IsOpen)
                {
                    _ = DialogHost.Show(new SplashScreenView()
                    {
                        DataContext = new { Msg = m.Msg }
                    }, "Root");
                }
                else
                {
                    DialogHost.Close("Root");
                }
            });
            //菜单执行相关动画及模板切换
            WeakReferenceMessenger.Default.Register <string, string>(view, "ExpandMenu", (sender, arg) =>
            {
                if (view.MENU.Width < 200)
                {
                    AnimationHelper.CreateWidthChangedAnimation(view.MENU, 60, 200, new TimeSpan(0, 0, 0, 0, 300));
                }
                else
                {
                    AnimationHelper.CreateWidthChangedAnimation(view.MENU, 200, 60, new TimeSpan(0, 0, 0, 0, 300));
                }

                //由于...
                var template = view.IC.ItemTemplateSelector;
                view.IC.ItemTemplateSelector = null;
                view.IC.ItemTemplateSelector = template;
            });
            base.SubscribeMessenger();
        }
Esempio n. 20
0
        public async Task WhenOnlySingleDialogHostIdentifierIsNullItShowsDialog()
        {
            DialogHost dialogHost2 = new();

            dialogHost2.ApplyDefaultStyle();
            dialogHost2.Identifier = Guid.NewGuid();

            try
            {
                dialogHost2.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
                Task showTask = DialogHost.Show("Content");
                Assert.True(DialogHost.IsDialogOpen(null));
                Assert.False(DialogHost.IsDialogOpen(dialogHost2.Identifier));
                DialogHost.Close(null);
                await showTask;
            }
            finally
            {
                dialogHost2.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));
            }
        }
Esempio n. 21
0
    public static async Task <object> ShowAsync(object model, string dialogName)
    {
        var view           = Instance.ViewManager.CreateAndBindViewForModelIfNecessary(model);
        var session        = DialogHost.GetDialogSession(dialogName);
        var sessionContext = (session?.Content as FrameworkElement)?.DataContext;

        if (model.Equals(sessionContext))
        {
            return(null);
        }

        if (DialogHost.IsDialogOpen(dialogName))
        {
            DialogHost.Close(dialogName);
        }

        (model as IScreenState)?.Activate();
        var result = await DialogHost.Show(view, dialogName).ConfigureAwait(true);

        (model as IScreenState)?.Deactivate();
        return(result);
    }
        private async void AddVideoToList(object s)
        {
            if (IsLoading || string.IsNullOrWhiteSpace(s as string))
            {
                return;
            }
            string url = (string)s;

            try
            {
                IsLoading = true;
                var videos = await _youtubeservise.GetVideosAsync(url);

                IReadOnlyList <VideoDownloadOption>?videoOptions;
                string?title = default;

                if (videos.Length == 1)
                {
                    videoOptions = await _youtubeservise.GetVideoDownloadOptionsAsync(url);
                }
                else
                {
                    videoOptions = YoutubeVideoService.GetOptionPlaylist().Reverse().ToArray();
                    title        = await _youtubeservise.GetPlaylistTitle(url);
                }
                IsLoading = false;
                DialogHost.Close("MainDialog", new YoutubeVideoModel(videos, videoOptions, title));
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            IsLoading = false;
        }
Esempio n. 23
0
 protected virtual void Save(DialogParameters param)
 {
     DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK, param));
 }
Esempio n. 24
0
        public void WhenClosingDialogThatIsNotOpenItThrowsDialogNotOpen()
        {
            var ex = Assert.Throws <InvalidOperationException>(() => DialogHost.Close(null));

            Assert.Equal("DialogHost is not open.", ex.Message);
        }
 private void Close_Click(object sender, RoutedEventArgs e)
 {
     DialogHost.Close("Main");
 }
Esempio n. 26
0
 void Close(DialogResult result)
 {
     DialogHost.Close(IdentifierName, result);
 }
Esempio n. 27
0
 private void SelectButton_Click(object sender, RoutedEventArgs e)
 {
     DialogHost.Close("PromptHost", SelectList.SelectedItem);
 }
Esempio n. 28
0
 public void CloseDialog() => DialogHost.Close("MainDialog");
Esempio n. 29
0
 protected virtual void Cancel()
 {
     DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.No));
 }
Esempio n. 30
0
 protected virtual void Save()
 {
     DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK));
 }