コード例 #1
0
 public void ShowWindow(Action <UserControl> beforeShow = null)
 {
     beforeShow?.Invoke(_uc);
     if (Vm.IsDialogWindow)
     {
         this.ShowInTaskbar         = false;
         this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
         var owner = TopWindow.GetTopWindow();
         if (this != owner)
         {
             this.Owner = owner;
         }
         double ownerOpacity = this.Owner.Opacity;
         this.Owner.Opacity = 0.6;
         this.ShowDialog();
         this.Owner.Opacity = ownerOpacity;
     }
     else
     {
         this.ShowActivated = true;
         this.Show();
         if (this.WindowState == WindowState.Minimized)
         {
             this.WindowState = WindowState.Normal;
         }
         this.Activate();
     }
 }
コード例 #2
0
        private DialogWindow(
            string icon,
            string title,
            string message,
            Action onYes,
            Action onNo)
        {
            InitializeComponent();
            ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources);
            this.Resources["Title"]   = title;
            this.Resources["Message"] = message;
            if (!string.IsNullOrEmpty(icon) && Application.Current.Resources.Contains(icon))
            {
                this.Resources["Icon"] = Application.Current.Resources[icon];
            }

            var owner = TopWindow.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
            _onYes = onYes;
            _onNo  = onNo;
            if (onYes != null || onNo != null)
            {
                this.BtnOk.Visibility = Visibility.Collapsed;
            }
            if (onYes == null && onNo == null)
            {
                this.BtnYes.Visibility = Visibility.Collapsed;
                this.BtnNo.Visibility  = Visibility.Collapsed;
            }
        }
コード例 #3
0
 public NTMinerFileEdit(string iconName, NTMinerFileViewModel vm)
 {
     this.DataContext = vm;
     InitializeComponent();
     this.PathIcon.Data = (Geometry)Application.Current.Resources[iconName];
     this.Owner         = TopWindow.GetTopWindow();
 }
コード例 #4
0
ファイル: CalcConfig.xaml.cs プロジェクト: TimeYM/ntminer
 public static void ShowWindow()
 {
     ContainerWindow.ShowWindow(new ContainerWindowViewModel {
         Title        = "收益计算器设置",
         IconName     = "Icon_Calc",
         Width        = 500,
         Height       = 450,
         CloseVisible = System.Windows.Visibility.Visible,
         SaveVisible  = System.Windows.Visibility.Visible,
         OnOk         = (uc) => {
             CalcConfigViewModels vm = (CalcConfigViewModels)uc.DataContext;
             NTMinerRoot.Current.CalcConfigSet.SaveCalcConfigs(vm.CalcConfigVms.Select(a => new CalcConfigData(a)).ToList());
             TopWindow.GetTopWindow()?.Close();
             return(true);
         }
     }, ucFactory: (window) => {
         var uc = new CalcConfig();
         uc.ItemsControl.MouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) => {
             if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
             {
                 window.DragMove();
             }
         };
         return(uc);
     }, fixedSize: false);
 }
コード例 #5
0
        public MinerClientAdd(MinerClientAddViewModel vm)
        {
            this.DataContext = vm;
            InitializeComponent();
            var owner = TopWindow.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
        }
コード例 #6
0
 private bool Login()
 {
     if (string.IsNullOrEmpty(SingleUser.LoginName) || string.IsNullOrEmpty(SingleUser.PasswordSha1))
     {
         LoginWindow window = new LoginWindow()
         {
             WindowStartupLocation = WindowStartupLocation.CenterOwner,
             Owner = TopWindow.GetTopWindow()
         };
         var result = window.ShowDialogEx();
         return(result.HasValue && result.Value);
     }
     return(true);
 }
コード例 #7
0
 public LangViewItemViewModel(Guid id)
 {
     _id       = id;
     this.Edit = new DelegateCommand(() => {
         LangViewItemEdit.ShowWindow(new LangViewItemViewModel(this));
     });
     this.Save = new DelegateCommand(() => {
         if (LangViewItemViewModels.Current.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateLangViewItemCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddLangViewItemCommand(this));
         }
         TopWindow.GetTopWindow()?.Close();
     });
 }
コード例 #8
0
 public NTMinerFileViewModel()
 {
     _id        = Guid.NewGuid();
     _publishOn = DateTime.Now;
     this.Save  = new DelegateCommand(() => {
         if (Login())
         {
             OfficialServer.FileUrlService.AddOrUpdateNTMinerFileAsync(new NTMinerFileData().Update(this), (response, e) => {
                 if (response.IsSuccess())
                 {
                     MainWindowViewModel.Instance.Refresh();
                     UIThread.Execute(() => {
                         TopWindow.GetTopWindow()?.Close();
                     });
                 }
                 else
                 {
                     Logger.ErrorDebugLine($"AddOrUpdateNTMinerFileAsync失败");
                 }
             });
         }
     });
     this.Edit = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("Icon_Edit", new NTMinerFileViewModel(this));
         window.ShowDialogEx();
     });
     this.Remove = new DelegateCommand(() => {
         if (Login())
         {
             this.ShowDialog(message: $"确定删除{this.Version}({this.VersionTag})吗?", title: "确认", onYes: () => {
                 OfficialServer.FileUrlService.RemoveNTMinerFileAsync(this.Id, (response, e) => {
                     MainWindowViewModel.Instance.SelectedNTMinerFile = MainWindowViewModel.Instance.NTMinerFiles.FirstOrDefault();
                     if (this == MainWindowViewModel.Instance.ServerLatestVm)
                     {
                         MainWindowViewModel.Instance.ServerLatestVm = MainWindowViewModel.Instance.NTMinerFiles
                                                                       .FirstOrDefault(a => a != this && a.VersionData > MainWindowViewModel.Instance.LocalNTMinerVersion);
                     }
                     MainWindowViewModel.Instance.Refresh();
                 });
             }, icon: IconConst.IconConfirm);
         }
     });
 }
コード例 #9
0
ファイル: InputWindow.xaml.cs プロジェクト: yuanaichi/ntminer
        public InputWindow(
            string title,
            string text,
            Func <string, string> check,
            Action <string> onOk)
        {
            InitializeComponent();
            TbTitle.Text = title;
            TbText.Text  = text;

            var owner = TopWindow.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
            _check = check;
            _onOk  = onOk ?? throw new ArgumentNullException(nameof(onOk));
        }
コード例 #10
0
 public void ShowWindow(Action <UserControl> beforeShow = null)
 {
     beforeShow?.Invoke(_uc);
     if (Vm.IsDialogWindow || Vm.HasOwner)
     {
         var owner = TopWindow.GetTopWindow();
         if (this != owner && owner != null)
         {
             this.Owner = owner;
         }
     }
     if (Vm.IsDialogWindow || Vm.HasOwner || Vm.HeaderVisible == Visibility.Collapsed)
     {
         this.ShowInTaskbar = false;
     }
     if (Vm.IsDialogWindow)
     {
         this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
         if (this.Owner != null)
         {
             double ownerOpacity = this.Owner.Opacity;
             this.Owner.Opacity = 0.6;
             this.ShowDialog();
             this.Owner.Opacity = ownerOpacity;
         }
         else
         {
             this.ShowDialog();
         }
     }
     else
     {
         this.Topmost       = Vm.IsTopMost;
         this.ShowActivated = true;
         this.Show();
         if (this.WindowState == WindowState.Minimized)
         {
             this.WindowState = WindowState.Normal;
         }
         this.Activate();
     }
 }
コード例 #11
0
 public NTMinerFileViewModel()
 {
     _id        = Guid.NewGuid();
     _publishOn = DateTime.Now;
     this.Save  = new DelegateCommand(() => {
         if (Login())
         {
             Server.FileUrlService.AddOrUpdateNTMinerFile(new NTMinerFileData().Update(this), response => {
                 if (response != null && response.IsSuccess())
                 {
                     MainWindowViewModel.Current.Refresh();
                     Execute.OnUIThread(() => {
                         TopWindow.GetTopWindow()?.Close();
                     });
                 }
             });
         }
     });
     this.Edit = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("编辑", "Icon_Edit", new NTMinerFileViewModel(this));
         window.ShowDialogEx();
     });
     this.Remove = new DelegateCommand(() => {
         if (Login())
         {
             DialogWindow.ShowDialog(message: $"确定删除{this.Version}({this.VersionTag})吗?", title: "确认", onYes: () => {
                 Server.FileUrlService.RemoveNTMinerFile(this.Id, isSuccess => {
                     MainWindowViewModel.Current.SelectedNTMinerFile = MainWindowViewModel.Current.NTMinerFiles.FirstOrDefault();
                     if (this == MainWindowViewModel.Current.ServerLatestVm)
                     {
                         MainWindowViewModel.Current.ServerLatestVm = MainWindowViewModel.Current.NTMinerFiles
                                                                      .FirstOrDefault(a => a != this && a.VersionData > MainWindowViewModel.Current.LocalNTMinerVersion);
                     }
                     MainWindowViewModel.Current.Refresh();
                 });
             }, icon: "Icon_Confirm");
         }
     });
 }
コード例 #12
0
        private DialogWindow(
            string icon,
            string title,
            string message,
            string helpUrl,
            Action onYes,
            Action onNo)
        {
            _helpUrl = helpUrl;
            InitializeComponent();
            if (!string.IsNullOrEmpty(helpUrl))
            {
                this.BtnHelp.Visibility = Visibility.Visible;
            }
            this.TextBlockTitle.Text   = title;
            this.TextBlockMessage.Text = message;
            if (!string.IsNullOrEmpty(icon) && Application.Current.Resources.Contains(icon))
            {
                this.Resources["Icon"] = Application.Current.Resources[icon];
            }

            var owner = TopWindow.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
            _onYes = onYes;
            _onNo  = onNo;
            if (onYes != null || onNo != null)
            {
                this.BtnOk.Visibility = Visibility.Collapsed;
            }
            if (onYes == null && onNo == null)
            {
                this.BtnYes.Visibility = Visibility.Collapsed;
                this.BtnNo.Visibility  = Visibility.Collapsed;
            }
        }
コード例 #13
0
        public static void ShowDialog(string icon    = null,
                                      string title   = null,
                                      string message = null,
                                      Action onYes   = null,
                                      Action onNo    = null)
        {
            Window window = new DialogWindow(icon, title, message, onYes, onNo);
            var    owner  = TopWindow.GetTopWindow();

            if (owner != window)
            {
                window.Owner = owner;
                double ownerOpacity = window.Owner.Opacity;
                window.Owner.Opacity = 0.6;
                window.ShowDialog();
                window.Owner.Opacity = ownerOpacity;
            }
            else
            {
                window.ShowDialog();
            }
        }
コード例 #14
0
        private DialogWindow(
            string icon,
            string title,
            string message,
            Action onYes,
            Action onNo)
        {
            InitializeComponent();
            var owner = TopWindow.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
            if (!string.IsNullOrEmpty(icon))
            {
                PathIcon.Data = (Geometry)Application.Current.Resources[icon];
            }
            if (!string.IsNullOrEmpty(title))
            {
                TxtTitle.Text = title;
            }
            if (!string.IsNullOrEmpty(message))
            {
                TxtMessage.Text = message;
            }
            _onYes = onYes;
            _onNo  = onNo;
            if (onYes != null || onNo != null)
            {
                this.BtnOk.Visibility = Visibility.Collapsed;
            }
            if (onYes == null && onNo == null)
            {
                this.BtnYes.Visibility = Visibility.Collapsed;
                this.BtnNo.Visibility  = Visibility.Collapsed;
            }
        }