예제 #1
0
        internal void RemoveHost(ContentControl cc)
        {
            // make sure it is not null
            if (cc == null)
            {
                return;
            }

            // make suer it is out host to begin with...
            if (!_hosts.Contains(cc))
            {
                return;
            }

            if (RegionHost.GetRegion(cc) != null)
            {
                RegionHost.SetRegion(cc, null);
            }


            _hosts.Remove(cc);

            // clear the binding
            ChangeHostContentProperty(cc, RegionHost.GetContentProperty(cc), null);
        }
예제 #2
0
        internal void AddHost(ContentControl cc)
        {
            // first let's make sure we acutally get something as parameter
            if (cc == null)
            {
                return;
            }

            // make sure the host really wants to be yours :-)
            if (RegionHost.GetRegion(cc) != _region)
            {
                RegionHost.SetRegion(cc, _region);
            }

            // now make sure it is not already in the list of hosts
            if (_hosts.Contains(cc))
            {
                return;
            }

            // so we actually need to set this as a new host
            _hosts.Add(cc);

            // remember to remove it when it is unloaded
            cc.Unloaded += _onHostUnloaded;

            // for window objects, unload is not enough, so we also listen to closed
            if (cc is Window w)
            {
                w.Closed += (s, e) =>
                {
                    RemoveHost(w);
                };
            }

            ChangeHostContentProperty(cc, null, RegionHost.GetContentProperty(cc));
        }