internal void DetachContent() { ModernContent content = this.Content as ModernContent; this.Content = null; this.CommandArea = null; if (content.StatusBar != null) { this.StatusBar = null; } DetachedWindowHost host = new DetachedWindowHost(content.DetachedName, content, detachedWindowClosed); DetachedContent.Add(host, content); host.Owner = this; host.Show(); if (host.Width < this.Width && host.Width < 1152) { host.Width = 1000; } if (host.Height < this.Height && host.Height < 800) { host.Height = 800; } this.IsContentDetached = true; this.Content = contentDetached; }
public DetachedWindowHost(string Title, ModernContent modernContent, EventHandler WindowClosedEvent) { ModernContent = modernContent; InitializeComponent(); windowCloseEvent = WindowClosedEvent; this.Title = Title ?? "Untitled"; }
/// <summary> /// Sub function of content loading /// </summary> /// <param name="content">The content.</param> /// <param name="AnimationShown">if set to <c>true</c> </param> /// <param name="story">The StoryBoard</param> /// <returns></returns> private bool LoadContentSub(ModernContent content, out bool AnimationShown, Storyboard story) { AnimationShown = false; if (content.IsDetachable) { this.IsContentDetachable = true; if (DetachedContent.ContainsValue(content)) { this.IsContentDetached = true; this.Content = contentDetached; return(true); } else { this.IsContentDetached = false; } } else { this.IsContentDetachable = false; this.IsContentDetached = false; } this.Content = content; this.CommandArea = content.CommandArea; if (content.StatusBar != null) { nextStatusBar = content.StatusBar; } else { nextStatusBar = this.DefaultStatusBar; } if (this.StatusBar != nextStatusBar) { if (this.StatusBar == null) { this.StatusBar = nextStatusBar; if (this.StatusBar != null) { this.StatusBar.BeginStoryboard(ShowStatusbarStoryboard); System.Diagnostics.Debug.WriteLine("BeginStoryboard Show line 79"); } } else { this.StatusBar.BeginStoryboard(HideStatusbarStoryboard); System.Diagnostics.Debug.WriteLine("BeginStoryboard Hide line 85"); } } content.BeginStoryboard(story); AnimationShown = true; System.Diagnostics.Debug.WriteLine("BeginStoryboard Show content"); return(false); }
private void detachedWindowClosed(object sender, EventArgs e) { DetachedWindowHost host = sender as DetachedWindowHost; ModernContent mc = DetachedContent[host]; DetachedContent.Remove(host); if (loadedMenu.ContentType == mc.GetType() && this.Content == contentDetached) { LoadContent(loadedMenu, out bool isLeft, out bool AnimationShown); } }
/// <summary> /// Release the memory for cached objects, and start immediate a Garbage collection. /// </summary> /// <remarks> /// Hummingbird UI holds the loaded contents in the cache to increase the performance, but it uses memory. /// </remarks> public void ClearCache() { ModernContent currentContent = this.Content as ModernContent; foreach (var v in Cache.Values) { if (v != currentContent) { v.Dispose(); } } Cache.Clear(); }
private void ModernWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (this.Content is ModernContent) { ModernContent currentContent = this.Content as ModernContent; if (currentContent.CanBeClosed()) { e.Cancel = false; } else { //The current content prevents close. e.Cancel = true; } } }
internal bool LoadContent(ModernMenuItem item, out bool isLeft, out bool AnimationShown) { int previousIndex, currentIndex; currentIndex = item.Index; previousIndex = 0; if (recentActions.Count > 0) { ModernMenuItem previousItem = recentActions.Peek() as ModernMenuItem; previousIndex = previousItem.Index; } isLeft = currentIndex <= previousIndex; System.Diagnostics.Debug.WriteLine("IsLeft=" + isLeft); AnimationShown = false; if (item.Items != null && item.Items.Count > 0) { return(true); } if (this.Content is ModernContent currentContent && !suppressCanBeClosed && !currentContent.CanBeClosed()) { return(false); } recentActions.Push(item); if (item.ContentType != null && item.ContentType.IsSubclassOf(typeof(ModernContent))) { Storyboard story = isLeft ? ((Storyboard)FindResource("ContentLeftInStoryboard")).Clone() : ((Storyboard)FindResource("ContentRightInStoryboard")).Clone(); if (Cache.ContainsKey(item)) { //item has already in the Cache ModernContent content = Cache[item]; loadedMenu = item; if (LoadContentSub(content, out AnimationShown, story)) { return(true); } } else { ModernContent content = (ModernContent)Activator.CreateInstance(item.ContentType); Cache.Add(item, content); loadedMenu = item; if (LoadContentSub(content, out AnimationShown, story)) { return(true); } } } else { this.Content = null; this.CommandArea = null; this.IsContentDetachable = false; this.IsContentDetached = false; loadedMenu = item; nextStatusBar = DefaultStatusBar; if (this.StatusBar != nextStatusBar) { if (this.StatusBar != null) { this.StatusBar.BeginStoryboard(HideStatusbarStoryboard); System.Diagnostics.Debug.WriteLine("Hide StatueBar line 190"); } else { this.StatusBar = nextStatusBar; if (this.StatusBar != null) { this.StatusBar.BeginStoryboard(ShowStatusbarStoryboard); System.Diagnostics.Debug.WriteLine("Show StatusBar line 198"); } } } } return(true); }