diff --git a/SoundBoard/Extensions.cs b/SoundBoard/Extensions.cs
index 063bc70..8284bf1 100644
--- a/SoundBoard/Extensions.cs
+++ b/SoundBoard/Extensions.cs
@@ -1,7 +1,9 @@
#region Usings
using System.Collections.Generic;
+using System.Windows;
using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
#endregion
@@ -71,4 +73,24 @@ public static bool IsBlack(this System.Windows.Media.Color color)
}
#endregion
+
+ #region TabItemExtensions class
+
+ ///
+ /// Extensions on the class.
+ ///
+ internal static class TabItemExtensions
+ {
+ ///
+ /// Returns if the given is the of its .
+ ///
+ ///
+ ///
+ public static bool IsSelectedItem(this TabItem tabItem)
+ {
+ return tabItem == (tabItem.Parent as TabControl)?.SelectedItem;
+ }
+ }
+
+ #endregion
}
diff --git a/SoundBoard/MainWindow.xaml.cs b/SoundBoard/MainWindow.xaml.cs
index cf30575..c8162b9 100644
--- a/SoundBoard/MainWindow.xaml.cs
+++ b/SoundBoard/MainWindow.xaml.cs
@@ -180,6 +180,8 @@ private void LoadSettings(string configFilePath)
if (tabNodes != null)
{
+ TabItem selectedTab = null;
+
foreach (XmlNode node in tabNodes)
{
string name = node["name"]?.InnerText;
@@ -187,6 +189,12 @@ private void LoadSettings(string configFilePath)
MetroTabItem tab = new MyMetroTabItem {Header = name};
Tabs.Items.Add(tab);
+ if (node.Attributes?["focused"]?.Value is string focusedString &&
+ bool.TryParse(focusedString, out bool focused) && focused)
+ {
+ selectedTab = tab;
+ }
+
List buttons = new List();
// Read the button data
@@ -222,6 +230,11 @@ private void LoadSettings(string configFilePath)
CreatePageContent(tab, buttons);
}
+ if (selectedTab is null == false)
+ {
+ Tabs.SelectedItem = selectedTab;
+ }
+
CreateTabContextMenus();
}
}
@@ -538,6 +551,7 @@ private void SaveSettings(string configFilePath)
{
string name = tab.Header.ToString();
textWriter.WriteStartElement("tab");
+ textWriter.WriteAttributeString("focused", tab.IsSelectedItem().ToString());
textWriter.WriteElementString("name", name);