コード例 #1
0
        public int AddMenuBarGroup(string topLevelMenuItemId, PreferredPosition positionInTopLevel, bool addSeparatorTopLevel,
                                   string subMenuItemId, PreferredPosition positionInSubLevel, bool addSeparatorSubLevel,
                                   object[] commands)
        {
            //m_Logger.Log(@"AddMenuBarGroup", Category.Debug, Priority.Medium);

#if DEBUG
            if (!Dispatcher.CheckAccess())
            {
                Debugger.Break();
            }
#endif

            int uid = generateNewUid();
            if (commands == null)
            {
#if DEBUG
                Debugger.Break();
#endif
                return(uid);
            }

            IRegion targetRegionTop;
            if (m_RegionManager.Regions.ContainsRegionWithName(topLevelMenuItemId))
            {
                targetRegionTop = m_RegionManager.Regions[topLevelMenuItemId];
            }
            else
            {
                var menuRoot = new MenuItemRichCommand
                {
                    Header = topLevelMenuItemId,
                    Name   = "MENU_ITEM_" + uid + @"__0",
                    HorizontalContentAlignment = HorizontalAlignment.Left,
                    VerticalContentAlignment   = VerticalAlignment.Center
                };

                //RegionManager.SetRegionManager(menuRoot, m_RegionManager);
                RegionManager.SetRegionName(menuRoot, topLevelMenuItemId);
                //RegionManager.UpdateRegions();

                MenuBarAnchor.Items.Add(menuRoot);

                targetRegionTop = m_RegionManager.Regions[topLevelMenuItemId];
            }

            int count = 0;


            bool needTopLevelSeparator = false;

            IRegion targetRegionSub = null;
            var     subRegionName   = subMenuItemId; // @"SubMenuRegion_" + uid;

            if (!string.IsNullOrEmpty(subRegionName))
            {
                if (m_RegionManager.Regions.ContainsRegionWithName(subRegionName))
                {
                    targetRegionSub       = m_RegionManager.Regions[subRegionName];
                    needTopLevelSeparator = false;
                }
                else
                {
                    needTopLevelSeparator = true;
                }
            }

            if (addSeparatorTopLevel && (needTopLevelSeparator || targetRegionSub == null))
            {
                object view = new MenuBarSeparator();
#if true || DEBUG
                if (PreferredPositionRegion.MARK_PREFERRED_POS)
                {
                    view = new MenuItem {
                        Header = positionInTopLevel.ToString("G") + " >> -------"
                    }
                }
                ;
#endif

                string viewname_ = (!string.IsNullOrEmpty(subMenuItemId) ? @"SUB_" : "")
                                   + uid + @"_" + count++;

                m_RegionManager.RegisterNamedViewWithRegion(targetRegionTop.Name,
                                                            new PreferredPositionNamedView {
                    m_viewName = viewname_, m_viewInstance = view, m_viewPreferredPosition = positionInTopLevel
                });
                //m_RegionManager.RegisterViewWithRegion(targetRegion.Name, () => sep);
                //targetRegion.Add(sep, viewname);
                //targetRegion.Activate(sep);
            }


            if (targetRegionSub == null && !string.IsNullOrEmpty(subRegionName))
            {
                string viewname = @"SUB_" + uid + @"_" + count++;

                var subMenuRoot = new MenuItemRichCommand
                {
                    Header = subMenuItemId,
                    Name   = "MENU_ITEM_" + viewname,
                    HorizontalContentAlignment = HorizontalAlignment.Left,
                    VerticalContentAlignment   = VerticalAlignment.Center
                };
#if true || DEBUG
                if (PreferredPositionRegion.MARK_PREFERRED_POS)
                {
                    subMenuRoot.Header = positionInTopLevel.ToString("G") + " >> " + subMenuRoot.Header;
                }
#endif
                //RegionManager.SetRegionManager(menuRoot, m_RegionManager);
                RegionManager.SetRegionName(subMenuRoot, subRegionName);
                //RegionManager.UpdateRegions();

                m_RegionManager.RegisterNamedViewWithRegion(targetRegionTop.Name,
                                                            new PreferredPositionNamedView {
                    m_viewName = viewname, m_viewInstance = subMenuRoot, m_viewPreferredPosition = positionInTopLevel
                });
                //m_RegionManager.RegisterViewWithRegion(targetRegion.Name, () => menuRoot);
                //targetRegion.Add(menuRoot); //, viewname);
                //targetRegion.Activate(menuRoot);

                targetRegionSub = m_RegionManager.Regions[subRegionName];
            }

            if (addSeparatorSubLevel && targetRegionSub != null)
            {
                object view = new MenuBarSeparator();
#if true || DEBUG
                if (PreferredPositionRegion.MARK_PREFERRED_POS)
                {
                    view = new MenuItem {
                        Header = positionInSubLevel.ToString("G") + " >> -------"
                    }
                }
                ;
#endif

                string viewname = uid + @"_" + count++;

                m_RegionManager.RegisterNamedViewWithRegion(targetRegionSub.Name,
                                                            new PreferredPositionNamedView {
                    m_viewName = viewname, m_viewInstance = view, m_viewPreferredPosition = positionInSubLevel
                });
                //m_RegionManager.RegisterViewWithRegion(targetRegion.Name, () => sep);
                //targetRegion.Add(sep, viewname);
                //targetRegion.Activate(sep);
            }

            var actualPosition = (string.IsNullOrEmpty(subMenuItemId) ? positionInTopLevel : positionInSubLevel);

            foreach (var command in commands)
            {
                if (command is RichDelegateCommand)
                {
#if true || DEBUG
                    if (PreferredPositionRegion.MARK_PREFERRED_POS)
                    {
                        string str = ((RichDelegateCommand)command).ShortDescription;
                        ((RichDelegateCommand)command).ShortDescription = actualPosition.ToString("G") + " >> " + str;
                    }
#endif
                    string viewname = uid + @"_" + count++;

                    m_RegionManager.RegisterNamedViewWithRegion((targetRegionSub ?? targetRegionTop).Name,
                                                                new PreferredPositionNamedView {
                        m_viewName = viewname, m_viewInstance = command, m_viewPreferredPosition = actualPosition
                    });
                    //m_RegionManager.RegisterViewWithRegion(targetRegion.Name, () => command);
                    //targetRegion.Add(command, viewname);
                    //targetRegion.Activate(command);
                }
                else if (command is TwoStateMenuItemRichCommand_DataContextWrapper)
                {
#if true || DEBUG
                    if (PreferredPositionRegion.MARK_PREFERRED_POS)
                    {
                        string str =
                            ((TwoStateMenuItemRichCommand_DataContextWrapper)command).RichCommandOne.ShortDescription;
                        ((TwoStateMenuItemRichCommand_DataContextWrapper)command).RichCommandOne.ShortDescription =
                            actualPosition.ToString("G") + " >> " + str;

                        str = ((TwoStateMenuItemRichCommand_DataContextWrapper)command).RichCommandTwo.ShortDescription;
                        ((TwoStateMenuItemRichCommand_DataContextWrapper)command).RichCommandTwo.ShortDescription =
                            actualPosition.ToString("G") + " >> " + str;
                    }
#endif
                    string viewname = uid + @"_" + count++;

                    m_RegionManager.RegisterNamedViewWithRegion((targetRegionSub ?? targetRegionTop).Name,
                                                                new PreferredPositionNamedView {
                        m_viewName = viewname, m_viewInstance = command, m_viewPreferredPosition = actualPosition
                    });
                    //m_RegionManager.RegisterViewWithRegion(targetRegion.Name, () => command);
                    //targetRegion.Add(command, viewname);
                    //targetRegion.Activate(command);
                }
            }

            return(uid);
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: S00190873/XmasExamSolution
 public override string ToString()
 {
     return($"{FirstName} {Surname} ({Age}) {PreferredPosition.ToString().ToUpper()} ");
 }