コード例 #1
0
ファイル: Tools.cs プロジェクト: raulalf7/ALF_TOOLS
        public static void ShowArgInfoControl(ArgInfo argInfo, TemplateInfoControl templateInfoControl, TemplateInfo templateInfo)
        {
            var w = new MetroWindow {Height = 430, Width = 600, EnableDWMDropShadow = true, ResizeMode = ResizeMode.NoResize};
            w.LostFocus += (ss, ee) => w.Focus();
            w.Title = "参数信息";
            w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            var control = new ArgInfoControl();
            control.Load(argInfo);

            control.OnCancelClose += (sender, args) => w.Close();

            control.OnOkClose += (ss, ee) =>
            {
                if (Tools.UpdateArgConfig(argInfo) != "")
                {
                    return;
                }
                templateInfoControl.Load(templateInfo, true);
                w.Close();
            };

            w.Content = control;
            w.ShowDialog();
        }
コード例 #2
0
        /// <summary>
        /// 导航到页面
        /// </summary>
        /// <param name="viewInfo">ViewInfo实例</param>
        private void navigateView(ViewInfo viewInfo)
        {
            //树形导航的内容
            var    module = viewInfo?.Module as Module;
            object view   = null;

            try
            {
                view = System.Reflection.Assembly.Load(module?.AssemblyName)
                       .CreateInstance(module?.ViewName);
                if (Equals(view, null))
                {
                    throw new NullReferenceException("加载模块时错误,页面未找到!");
                }
            }
            catch (Exception ex)
            {
                string msg = $"加载{module?.Name}{module?.AssemblyName}时错误,请确认模块名称和页面名称配置正确!{System.Environment.NewLine}{TypeExtensions.GetPropertiesValue<Module>(module)}{System.Environment.NewLine}{ex.Message}{System.Environment.NewLine}{ex.StackTrace}";
                LogHelper.Logger.Error(msg, ex);
                (Application.Current.MainWindow as MetroWindow).ShowMessageAsync("系统错误", msg);
                return;
            }

            switch (viewInfo.ViewType)
            {
            case ViewType.DockableView:    //可停靠的页面
            default:
                #region DockableView
                try
                {
                    if (layoutDocumentPane.Children.Any(a => a.ContentId == module?.Id.ToString()))
                    {
                        var tmp = layoutDocumentPane.Children.FirstOrDefault(a => a.ContentId == module?.Id.ToString());
                        tmp.IsActive = true;
                        return;
                    }
                    LayoutDocument layoutDocument = new LayoutDocument();
                    layoutDocument.Title     = module?.Name;
                    layoutDocument.ContentId = module?.Id.ToString();
                    layoutDocument.ToolTip   = layoutDocument.Title;
                    var icon = Utility.Windows.BitmapImageHelper.GetBitmapImage(module?.Icon, 16, 16);
                    layoutDocument.IconSource        = icon;
                    (view as UserControlBase).Margin = (Thickness)Utility.Windows.ResourceHelper.FindResource("UserControlMargin");
                    var viewModelBase = (view as UserControlBase)?.DataContext as ViewModelBase;
                    if (!Equals(viewModelBase, null))
                    {
                        viewModelBase.Parameter.Add(new KeyValuePair <string, object>(ParentName, layoutDocument));
                        if (!Equals(viewInfo.Parameter))
                        {
                            viewModelBase.Parameter.Add(new KeyValuePair <string, object>(DataModelName, viewInfo.Parameter));
                        }
                    }
                    layoutDocument.Content = view;
                    layoutDocumentPane.Children.Add(layoutDocument);
                    layoutDocument.IsActive = true;
                    Application.Current.MainWindow.Cursor = Cursors.Arrow;
                    LogHelper.Logger.Info($"{StaticData.CurrentUser?.Name }/{StaticData.CurrentUser?.NickName},打开{module?.Name}模块");
                }
                catch (Exception ex)
                {
                    string msg = $"加载{module?.AssemblyName}时错误,请确认模块名称和页面名称配置正确!{System.Environment.NewLine}{TypeExtensions.GetPropertiesValue<Module>(module)}{System.Environment.NewLine}{ex.Message }{System.Environment.NewLine}{ex.StackTrace}";
                    LogHelper.Logger.Error(msg, ex);
                    (Application.Current.MainWindow as MetroWindow).ShowMessageAsync("系统错误", msg);
                }
                #endregion
                break;

            case ViewType.MetroPopup:    //Metro蒙版模式对话框
                #region MetroPopup
                try
                {
                    var customDialog = new CustomDialog()
                    {
                        Title = module.Name
                    };
                    var userControlBase = view as UserControlBase;
                    var viewModelBase   = userControlBase.DataContext as ViewModelBase;
                    if (!Equals(viewModelBase, null))
                    {
                        viewModelBase.Parameter.Add(new KeyValuePair <string, object>(ParentName, customDialog));
                        if (!Equals(viewInfo.Parameter))
                        {
                            viewModelBase.Parameter.Add(new KeyValuePair <string, object>(DataModelName, viewInfo.Parameter));
                        }
                    }
                    customDialog.Content = view;
                    LogHelper.Logger.Info($"{StaticData.CurrentUser?.Name }/{StaticData.CurrentUser?.NickName},打开{module?.Name}Metro对话框模块");
                    var windows = Application.Current.MainWindow as MahApps.Metro.Controls.MetroWindow;
                    windows?.ShowMetroDialogAsync(customDialog);
                }
                catch (Exception ex)
                {
                    string msg = $"加载{module?.AssemblyName}时错误,请确认模块名称和页面名称配置正确!{System.Environment.NewLine}{TypeExtensions.GetPropertiesValue<Module>(module)}{System.Environment.NewLine}{ex.Message }{System.Environment.NewLine}{ex.StackTrace}";
                    LogHelper.Logger.Error(msg, ex);
                    (Application.Current.MainWindow as MetroWindow).ShowMessageAsync("系统错误", msg);
                }
                #endregion
                break;

            case ViewType.Popup:    //模式对话框弹出窗体
                #region Popup
                try
                {
                    MahApps.Metro.Controls.MetroWindow popupWindows = new MahApps.Metro.Controls.MetroWindow();
                    //popupWindows.TitlebarHeight = 25;
                    popupWindows.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    popupWindows.Style                     = Utility.Windows.ResourceHelper.FindResource(@"CleanWindowStyleKey") as Style;
                    popupWindows.WindowTitleBrush          = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsTitleColorBrush") as System.Windows.Media.Brush;
                    popupWindows.NonActiveWindowTitleBrush = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsTitleColorBrush") as System.Windows.Media.Brush;
                    popupWindows.Background                = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsBackgroundColorBrush") as System.Windows.Media.Brush;
                    popupWindows.GlowBrush                 = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsGlowBrush") as System.Windows.Media.Brush;
                    popupWindows.Owner                     = Application.Current.MainWindow.IsInitialized == false ? null : Application.Current.MainWindow;
                    popupWindows.ResizeMode                = ResizeMode.NoResize;
                    popupWindows.IsCloseButtonEnabled      = true;
                    popupWindows.ShowCloseButton           = true;
                    popupWindows.Width                     = (view as UserControlBase).Width + popupWindows.BorderThickness.Left + popupWindows.BorderThickness.Right;
                    popupWindows.Height                    = (view as UserControlBase).Height + popupWindows.TitlebarHeight;
                    popupWindows.Title                     = module?.Name;
                    //有则使用配置的图标,没有则使用默认的图标,再没有则使用主窗体的图标
                    popupWindows.Icon =
                        Utility.Windows.BitmapImageHelper.GetBitmapImage(module?.Icon)
                        ?? Utility.Windows.BitmapImageHelper.GetBitmapImage(@"pack://*****:*****@"CleanWindowStyleKey") as Style;
                    singleWindows.WindowTitleBrush          = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsTitleColorBrush") as System.Windows.Media.Brush;
                    singleWindows.NonActiveWindowTitleBrush = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsTitleColorBrush") as System.Windows.Media.Brush;
                    singleWindows.Background                = Utility.Windows.ResourceHelper.FindResource(@"PopupWindowsBackgroundColorBrush") as System.Windows.Media.Brush;
                    singleWindows.GlowBrush                 = Utility.Windows.ResourceHelper.FindResource(@"AccentColorBrush") as System.Windows.Media.Brush;
                    //singleWindows.Owner = Application.Current.MainWindow.IsInitialized == false ? null : Application.Current.MainWindow;
                    singleWindows.IsCloseButtonEnabled = true;
                    singleWindows.ShowCloseButton      = true;
                    singleWindows.Width  = (view as UserControlBase).Width + singleWindows.BorderThickness.Left + singleWindows.BorderThickness.Right;
                    singleWindows.Height = (view as UserControlBase).Height + singleWindows.TitlebarHeight;
                    singleWindows.Title  = module?.Name;
                    //有则使用配置的图标,没有则使用默认的图标,再没有则使用主窗体的图标
                    singleWindows.Icon =
                        Utility.Windows.BitmapImageHelper.GetBitmapImage(module?.Icon)
                        ?? Utility.Windows.BitmapImageHelper.GetBitmapImage(@"pack://application:,,,/Desktop.Resource;component/Images/Logo_128.ico")
                        ?? Application.Current.MainWindow.Icon;
                    var viewModelBase = (view as UserControlBase)?.DataContext as ViewModelBase;
                    if (!Equals(viewModelBase, null))
                    {
                        viewModelBase.Parameter.Add(new KeyValuePair <string, object>(ParentName, singleWindows));
                        if (!Equals(viewInfo.Parameter))
                        {
                            viewModelBase.Parameter.Add(new KeyValuePair <string, object>(DataModelName, viewInfo.Parameter));
                        }
                    }
                    singleWindows.ShowInTaskbar = true;
                    singleWindows.Content       = view;
                    singleWindows.Closed       += windows_Closed;
                    singleWindows.MouseDown    += popupWindows_MouseDown;
                    singleWindows.Focus();
                    singleWindows.Show();
                }
                catch (Exception ex)
                {
                    string msg = $"加载{module?.AssemblyName}时错误,请确认模块名称和页面名称配置正确!{System.Environment.NewLine}{TypeExtensions.GetPropertiesValue<Module>(module)}{System.Environment.NewLine}{ex.Message }{System.Environment.NewLine}{ex.StackTrace}";
                    LogHelper.Logger.Error(msg, ex);
                    (Application.Current.MainWindow as MetroWindow).ShowMessageAsync("系统错误", msg);
                }
                #endregion
                break;
            }
        }
コード例 #3
0
        /// <summary>
        /// 页面导航跳转,生成新页面
        /// </summary>
        /// <param name="viewInfo">页面信息</param>
        private void navigate(ViewInfo viewInfo)
        {
            Application.Current.MainWindow.Cursor = Cursors.Wait;

            UserControlBase view = null;

            if (Equals(viewInfo, null))
            {
                Application.Current.Resources["UiMessage"] = "未找到页面信息,请确认MenuFunctionViewInfoMap.json配置正确!";
                LogHelper.Info(Application.Current.Resources["UiMessage"].ToString());
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }
            //已经打开则激活
            if (layoutDocumentPane.Children.Any(a => a.Title == viewInfo.DisplayName.ToString()))
            {
                var tmp = layoutDocumentPane.Children.FirstOrDefault(a => a.Title == viewInfo.DisplayName.ToString());
                tmp.IsActive = true;

                Application.Current.Resources["UiMessage"] = $"{viewInfo.DisplayName} 页面已经打开,设置激活成功!";
                Application.Current.MainWindow.Cursor      = Cursors.Arrow;

                return;
            }

            try
            {
                view = System.Reflection.Assembly.Load(viewInfo.ViewAssemblyName)
                       .CreateInstance(viewInfo.ViewName) as UserControlBase;
            }
            catch (Exception ex)
            {
                Application.Current.Resources["UiMessage"] = "未找到页面:" + viewInfo.ViewName + ex.Message;
                LogHelper.Error(Application.Current.Resources["UiMessage"] + viewInfo.ToString(), ex);
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }

            if (Equals(view, null))
            {
                Application.Current.Resources["UiMessage"] = "未找到页面:" + viewInfo.ViewName;
                LogHelper.Info(Application.Current.Resources["UiMessage"] + viewInfo.ToString());
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }

            VmBase viewModel = null;

            try
            {
                viewModel = System.Reflection.Assembly.Load(viewInfo.ViewModelAssemblyName)
                            .CreateInstance(viewInfo.ViewModelName) as VmBase;
            }
            catch (Exception ex)
            {
                Application.Current.Resources["UiMessage"] = "未找到ViewModel:" + viewInfo.ViewModelName;
                LogHelper.Error(Application.Current.Resources["UiMessage"] + viewInfo.ToString(), ex);
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }
            if (Equals(viewModel, null))
            {
                Application.Current.Resources["UiMessage"] = "未找到ViewModel:" + viewInfo.ViewModelName;
                LogHelper.Info(Application.Current.Resources["UiMessage"] + viewInfo.ToString());
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }
            //Application.Current.Resources["UiMessage"] = viewInfo.DisplayName;
            //LogHelper.Info(Application.Current.Resources["UiMessage"] + viewInfo.ToString());
            //view.Parameter = viewInfo.Parameter;
            //viewModel.Parameter = view.Parameter;
            viewModel.Parameter  = viewInfo.Parameter;
            viewModel.MenuModule = viewInfo.MenuModule;
            view.DataContext     = viewModel;
            //根据页面类型生成页面
            switch (viewInfo.ViewType)
            {
            case ViewType.PopupNoTitle:     //没有标题栏的页面
                MahApps.Metro.Controls.MetroWindow popupNoTitleWindows = new MahApps.Metro.Controls.MetroWindow();
                popupNoTitleWindows.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                popupNoTitleWindows.Style                 = Utility.Windows.ResourceHelper.FindResource(@"CleanWindowStyleKey") as Style;
                popupNoTitleWindows.GlowBrush             = Utility.Windows.ResourceHelper.FindResource(@"AccentColorBrush") as System.Windows.Media.Brush;
                popupNoTitleWindows.Owner                 = Application.Current.MainWindow.IsInitialized == false ? null : Application.Current.MainWindow;
                popupNoTitleWindows.ResizeMode            = ResizeMode.NoResize;
                popupNoTitleWindows.IsCloseButtonEnabled  = false;
                popupNoTitleWindows.ShowInTaskbar         = popupNoTitleWindows.Owner == null ? true : false;
                popupNoTitleWindows.MouseDown            += PopupWindows_MouseDown;
                popupNoTitleWindows.ShowCloseButton       = false;
                popupNoTitleWindows.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                popupNoTitleWindows.Width                 = view.Width;
                popupNoTitleWindows.Height                = view.Height;
                popupNoTitleWindows.TitlebarHeight        = 0;
                //有限实用配置的图标,没有则使用默认的图标,没有则使用主窗体的
                popupNoTitleWindows.Icon =
                    Utility.Windows.BitmapImageHelper.GetBitmapImage(viewInfo.Icon)
                    ?? Utility.Windows.BitmapImageHelper.GetBitmapImage(@"pack://*****:*****@"CleanWindowStyleKey") as Style;
                popupWindows.GlowBrush            = Utility.Windows.ResourceHelper.FindResource(@"AccentColorBrush") as System.Windows.Media.Brush;
                popupWindows.Owner                = Application.Current.MainWindow.IsInitialized == false ? null : Application.Current.MainWindow;
                popupWindows.ResizeMode           = ResizeMode.NoResize;
                popupWindows.IsCloseButtonEnabled = false;
                popupWindows.ShowCloseButton      = false;
                popupWindows.Width                = view.Width;
                popupWindows.Height               = view.Height;
                popupWindows.Title                = viewInfo.DisplayName;
                //有则使用配置的图标,没有则使用默认的图标,再没有则使用主窗体的图标
                popupWindows.Icon =
                    Utility.Windows.BitmapImageHelper.GetBitmapImage(viewInfo.Icon)
                    ?? Utility.Windows.BitmapImageHelper.GetBitmapImage(@"pack://*****:*****@"pack://application:,,,/Solution.Desktop.Resource;component/Images/logo_16x16.ico")
                    ?? Application.Current.MainWindow.Icon;
                layoutDocument.Content = view;
                layoutDocumentPane.Children.Add(layoutDocument);
                layoutDocument.IsActive = true;
                layoutDocument.Closed  += LayoutDocument_Closed;
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                break;

            case ViewType.SingleWindow:    //单个视图。主要为了显示帮助窗口
                MahApps.Metro.Controls.MetroWindow singleWindows = new MahApps.Metro.Controls.MetroWindow();
                singleWindows.TitlebarHeight        = 23;
                singleWindows.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                singleWindows.Style     = Utility.Windows.ResourceHelper.FindResource(@"CleanWindowStyleKey") as Style;
                singleWindows.GlowBrush = Utility.Windows.ResourceHelper.FindResource(@"AccentColorBrush") as System.Windows.Media.Brush;
                singleWindows.Content   = view;
                singleWindows.Width     = view.Width;
                singleWindows.Height    = view.Height;
                singleWindows.Title     = viewInfo.DisplayName;
                //有则使用配置的图标,没有则使用默认的图标,再没有则使用主窗体的图标
                singleWindows.Icon =
                    Utility.Windows.BitmapImageHelper.GetBitmapImage(viewInfo.Icon)
                    ?? Utility.Windows.BitmapImageHelper.GetBitmapImage(@"pack://application:,,,/Solution.Desktop.Resource;component/Images/logo_16x16.ico")
                    ?? Application.Current.MainWindow.Icon;
                singleWindows.Closed += Window_Closed;

                singleWindows.Show();
                singleWindows.Focus();
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// 页面跳转,之后的所有页面在此函数经行
        /// </summary>
        /// <param name="viewInfo"></param>
        private void Navigate(ViewInfo viewInfo)
        {
            MyUserControlBase view;


            if (Equals(viewInfo.Parameter, null))
            {
                var assemblyName = viewInfo.ViewName.ToDescription().Split(',');
                if (assemblyName.Length > 1)
                {
                    view =
                        System.Reflection.Assembly.Load(assemblyName[0])
                        .CreateInstance(assemblyName[1]) as MyUserControlBase;
                }
                else
                {
                    view =
                        System.Reflection.Assembly.Load(@"House.UserControls")
                        .CreateInstance(assemblyName[0]) as MyUserControlBase;
                }
            }
            else
            {
                var assemblyName = viewInfo.ViewName.ToDescription().Split(',');
                if (assemblyName.Length > 1)
                {
                    view =
                        System.Reflection.Assembly.Load(assemblyName[0])
                        .CreateInstance(assemblyName[1], true, System.Reflection.BindingFlags.Default,
                                        null, new[] { viewInfo.Parameter }, null, null) as MyUserControlBase;
                }
                else
                {
                    view =
                        System.Reflection.Assembly.Load(@"House.UserControls")
                        .CreateInstance(assemblyName[0], true, System.Reflection.BindingFlags.Default,
                                        null, new[] { viewInfo.Parameter }, null, null) as MyUserControlBase;
                }
            }

            if (view == null)
            {//未找到视图,抛出异常
                //throw new Exception(viewInfo.ViewName.ToString());
                this.RootPanel.Content = "视图加载失败请联系客服";
            }

            if ((view as MainMenu.Views.MainMenuView2) != null)
            {
                this.restoreBtn.Visibility = Visibility;
            }
            else
            {
                this.restoreBtn.Visibility = Visibility.Collapsed;
            }

            switch (viewInfo.ViewType)
            {
            case ViewType.Popup:    //模式对话框
                MahApps.Metro.Controls.MetroWindow popupWindows = new MahApps.Metro.Controls.MetroWindow();
                popupWindows.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                popupWindows.Style     = FindResource(@"CleanWindowStyleKey") as Style;
                popupWindows.GlowBrush = FindResource(@"AccentColorBrush") as System.Windows.Media.Brush;
                //变更语言时,动态更新对话框Title,Title取决于控件的Tag
                popupWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.TitleProperty, new Binding(@"Tag")
                {
                    Source = view
                });
                popupWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.WidthProperty, new Binding(@"Width")
                {
                    Source = view
                });
                popupWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.HeightProperty, new Binding(@"Height")
                {
                    Source = view
                });
                popupWindows.Owner                = Application.Current.MainWindow;
                popupWindows.ResizeMode           = ResizeMode.NoResize;
                popupWindows.IsCloseButtonEnabled = false;
                popupWindows.ShowCloseButton      = false;
                //popupWindows.Icon = new BitmapImage(new Uri("pack://*****:*****@"AccentColorBrush") as System.Windows.Media.Brush;
                //变更语言时,动态更新对话框Title,Title取决于控件的Tag
                singleWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.TitleProperty, new Binding(@"Tag")
                {
                    Source = view
                });
                singleWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.WidthProperty, new Binding(@"Width")
                {
                    Source = view
                });
                singleWindows.SetBinding(MahApps.Metro.Controls.MetroWindow.HeightProperty, new Binding(@"Height")
                {
                    Source = view
                });
                singleWindows.Content    = view;
                singleWindows.ResizeMode = ResizeMode.NoResize;
                //singleWindows.ShowIconOnTitleBar = true;
                singleWindows.Icon = new BitmapImage(new Uri("pack://application:,,,/House.Thems;component/Images/Logo.ico", UriKind.Absolute));
                //singleWindows.Icon = Utility.Windows.ResourceHelper.FindResource("pack://application:,,,/SuperSoft.Resource.Default;component/Images/Logo_White.png");
                //singleWindows.IsCloseButtonEnabled = true;
                //singleWindows.ShowCloseButton = true;
                //singleWindows.Owner = Application.Current.MainWindow;
                singleWindows.Topmost = true;
                singleWindows.Show();
                singleWindows.Focus();
                break;
            }
        }