Click or drag to resize

WPF Tabs Handling

WPF tabs handling. Sets the last selected tab.

This topic contains the following sections:

Project Properties

Go to "Solution Explorer", project "Properties", tab "Settings"

Create a entry item called TabPageIndex of type "int" on scope "User"

WPF Windows

Class based on WPF Window

C#
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    //...
}

Construtor - sets tab

C#
/// <summary>
/// Initializes a new instance of the MainWindow class.
/// Constructor without parameter
/// </summary>
public MainWindow()
{
    InitializeComponent();
    this.TabMain.SelectedIndex = Properties.Settings.Default.TabPageIndex;

    // ... 
}

Tab selection handling

C#
/// <summary>
/// Tab selection changed
/// </summary>
/// <param name="sender">TabMain object</param>
/// <param name="e"></param>
private void TabMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Properties.Settings.Default.TabPageIndex = TabMain.SelectedIndex;
}

Save settings

C#
/// <summary>
/// Save settings
/// </summary>
protected override void OnClosing(CancelEventArgs e)
{
    SOWIWin.Tool.Properties.Settings.Default.Save();
    base.OnClosing(e);
}