public void AddChild(IHierarchicalViewModel child, bool allowDuplicateNames = false)
        {
            if (_Children == null)
            {
                _Children = new ObservableCollection <IHierarchicalViewModel>();
            }
            if (!allowDuplicateNames)
            {
                if (CheckForNameConflict(child))
                {
                    //silently fix the name?
                    int    i        = 1;
                    string prevname = child.Name;
                    do
                    {
                        child.Name = prevname + "_" + i;
                        i++;
                    } while (CheckForNameConflict(child));
                }
            }
            //check interfaces for events to add handlers for.
            if (child is INavigate)
            {
                INavigate ele = child as INavigate;
                ele.NavigationEvent += Navigate;
            }
            if (child is Base.Interfaces.IReportMessage)
            {
                Base.Interfaces.IReportMessage ele = child as Base.Interfaces.IReportMessage;
                Base.Implementations.MessageHub.Register(ele);
            }
            //if (child.GetType().GetInterfaces().Contains(typeof(ICanClose)))
            //{
            //    ICanClose ele = child as ICanClose;
            //    ele.Close += RequestClose;
            //}

            _Children.Add(child);
            child.Parent = this;
            NotifyPropertyChanged(nameof(Children));
        }
示例#2
0
 public ReporterRemovedEventArgs(Base.Interfaces.IReportMessage reporter)
 {
     _reporter = reporter;
 }
示例#3
0
 public static void Unregister(Base.Interfaces.IReportMessage messanger)
 {
     messanger.MessageReport -= Broadcast;
     _reporters.Remove(messanger);
     ReporterRemoved?.Invoke(null, new ReporterRemovedEventArgs(messanger));
 }
示例#4
0
 public static void Register(Base.Interfaces.IReportMessage messanger)
 {
     messanger.MessageReport += Broadcast;
     _reporters.Add(messanger);
     ReporterAdded?.Invoke(null, new ReporterAddedEventArgs(messanger));
 }