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); }
private Task _ensureWindowOpen(RegionService service) { if (!service.Hosts.OfType <Window>().Any()) { var w = new Window(); w.Unloaded += (s, e) => { var action = _onClosing; _onClosing = null; action?.Invoke(); }; Application.Current.Exit += (s, e) => { var action = _onClosing; _onClosing = null; action?.Invoke(); }; _myWindows.Add(w); w.Style = WindowStyle; RegionHost.SetRegion(w, service.Region); w.Show(); } return(Tasks.Empty); }
private Task _ensureWindowOpen(RegionService service) { if (!service.Hosts.OfType <Window>().Any()) { var w = new Window(); w.SizeToContent = SizeToContent; w.WindowStartupLocation = WindowStartupLocation; _myWindows.Add(w); w.Style = WindowStyle; RegionHost.SetRegion(w, service.Region); // simply calling ShowDialog will block the method, so e need to trick it... w.Dispatcher.BeginInvoke(new Action(() => { // make sure window was not closed since dispatching if (_myWindows.Contains(w)) { w.ShowDialog(); } })); } return(Tasks.Empty); }
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)); }