当前位置: 首页>>代码示例>>C#>>正文


C# MenuItem.AddHandler方法代码示例

本文整理汇总了C#中System.Windows.Controls.MenuItem.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.AddHandler方法的具体用法?C# MenuItem.AddHandler怎么用?C# MenuItem.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.MenuItem的用法示例。


在下文中一共展示了MenuItem.AddHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateControls

        private UIElement CreateControls()
        {
            m_menu_main = new Menu();

            ////////
            // File
            m_menuItem_loadFromDatabase = new MenuItem() { Header = "Load DB" };
            m_menuItem_loadFromDatabase.Click += MenuItem_LoadFromDatabase_Click;

            m_menuItem_exportToXml = new MenuItem() { Header = "Export to Xml" };
            m_menuItem_exportToXml.Click += MenuItem_ExportToXml_Click;

            m_menuItem_importFromXml = new MenuItem() { Header = "Import From Xml" };
            m_menuItem_importFromXml.Click += MenuItem_ImportFromXml_Click;

            m_menuItem_file = new MenuItem() { Header = "File" };
            m_menuItem_file.Items.Add(m_menuItem_loadFromDatabase);

            m_menu_main.Items.Add(m_menuItem_file);

            ////////
            // Setup
            m_menuItem_GameStateOnInitialLoad = new MenuItem() { Header = "Area/Room On Initial Load" };
            RoutedEventHandler menuItem_GameStateOnInitialLoad_clickHandler =
                new RoutedEventHandler((x, y) =>
                {
                    if (m_menuItem_GameStateOnInitialLoad.IsSubmenuOpen)
                        m_menuItem_setup.IsSubmenuOpen = false;
                });
            m_menuItem_GameStateOnInitialLoad.AddHandler(Button.ClickEvent, menuItem_GameStateOnInitialLoad_clickHandler);
            m_menuItem_GameStateOnInitialLoad.AddHandler(MenuItem.ClickEvent, menuItem_GameStateOnInitialLoad_clickHandler);

            m_menuItem_setup = new MenuItem() { Header = "Setup" };
            m_menuItem_setup.Items.Add(m_menuItem_GameStateOnInitialLoad);

            ////////
            // Toolbar
            DockPanel dockPanel_main = new DockPanel();
            dockPanel_main.Children.Add(m_menu_main);
            DockPanel.SetDock(m_menu_main, Dock.Top);

            ////////
            // grid
            m_grid_main = new Grid();
            m_grid_main.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            m_grid_main.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(100.0, GridUnitType.Star) });
            m_grid_main.SetGridRowColumn(dockPanel_main, 0, 0);

            return m_grid_main;
        }
开发者ID:ianeller-romey,项目名称:GinTub_TLATEOTH,代码行数:50,代码来源:MainWindow.xaml.cs

示例2: Construct

        public static MenuItem Construct(SearchControl sc, MenuItem plainExcelMenuItem)
        {
            MenuItem miResult = new MenuItem
            {
                Header = ExcelMessage.Reports.NiceToString(),
                Icon = ExtensionsImageLoader.GetImageSortName("excel.png").ToSmallImage()

            };

            miResult.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler((object sender, RoutedEventArgs e) =>
            {
                e.Handled = true;

                if (e.OriginalSource is MenuItem) //Not to capture the mouseDown of the scrollbar buttons
                {
                    MenuItem b = (MenuItem)e.OriginalSource;
                    Lite<ExcelReportEntity> reportLite = (Lite<ExcelReportEntity>)b.Tag;
                    
                    SaveFileDialog sfd = new SaveFileDialog()
                    {
                        AddExtension = true,
                        DefaultExt = ".xlsx",
                        Filter = ExcelMessage.Excel2007Spreadsheet.NiceToString(),
                        FileName = reportLite.ToString() + " - " + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx",
                        OverwritePrompt = true,
                        Title = ExcelMessage.FindLocationFoExcelReport.NiceToString()
                    };

                    if (sfd.ShowDialog(Window.GetWindow(sc)) == true)
                    {
                        byte[] result = Server.Return((IExcelReportServer r) => r.ExecuteExcelReport(reportLite, sc.GetQueryRequest(true)));

                        File.WriteAllBytes(sfd.FileName, result);

                        System.Diagnostics.Process.Start(sfd.FileName);
                    }
                }
            }));

            Action initialize = null;

            MenuItem miAdmin = new MenuItem()
            {
                Header = "Administrar",
                Icon = ExtensionsImageLoader.GetImageSortName("folderedit.png").ToSmallImage()
            };

            miAdmin.Click += (object sender, RoutedEventArgs e)=>
            {
                var query = QueryClient.GetQuery(sc.QueryName);

                Finder.Explore(new ExploreOptions(typeof(ExcelReportEntity))
                {
                    ShowFilters = false,
                    ShowFilterButton = false,
                    FilterOptions = new List<FilterOption>
                    {
                        new FilterOption 
                        { 
                            ColumnName = "Query", 
                            Operation = FilterOperation.EqualTo, 
                            Value = query.ToLite(query.IsNew),
                            Frozen = true
                        }
                    },
                    Closed = (_, __) => miAdmin.Dispatcher.Invoke(() => initialize()) //Refrescar lista de informes tras salir del administrador
                });

                e.Handled = true;
            };

            initialize = ()=>
            {
                miResult.Items.Clear();

                List<Lite<ExcelReportEntity>> reports = Server.Return((IExcelReportServer s)=>s.GetExcelReports(sc.QueryName));

                if (plainExcelMenuItem != null)
                {
                    miResult.Items.Add(plainExcelMenuItem);
                    miResult.Items.Add(new Separator());
                }

                miResult.Header = new TextBlock { Inlines = { new Run(ExcelMessage.Reports.NiceToString()), reports.Count == 0? (Inline)new Run(): new Bold(new Run(" (" + reports.Count + ")")) } };

                if (reports.Count > 0)
                {
                    foreach (Lite<ExcelReportEntity> report in reports)
                    {
                        MenuItem mi = new MenuItem()
                        {
                            Header = report.ToString(),
                            Icon = ExtensionsImageLoader.GetImageSortName("excelDoc.png").ToSmallImage(),
                            Tag = report,
                        };
                        miResult.Items.Add(mi);
                    }
                }          

          
//.........这里部分代码省略.........
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:101,代码来源:ReportMenuItem.cs


注:本文中的System.Windows.Controls.MenuItem.AddHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。