/// <summary>
        /// Handle the delete member button click event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnDeleteMemberButton(object sender, RoutedEventArgs args)
        {
            Team      team      = (Team)TeamSelectionComboBox.SelectedItem;
            MemberTab memberTab = (MemberTab)MemberTypeTabControl.SelectedItem;

            // Find a child data-grid of the tab control
            DataGrid membersDataGrid = (DataGrid)MemberTypeTabControl.GetChildren().Find(control => control is DataGrid);

            // If we haven't selecting anything in the data grid, we can't remove anything
            if (membersDataGrid.SelectedItem == null)
            {
                return;
            }

            int currentSelectedIndex = membersDataGrid.SelectedIndex;

            team.RemoveMember(memberTab.MemberType, (Member)membersDataGrid.SelectedItem);

            if (currentSelectedIndex == membersDataGrid.Items.Count)
            {
                currentSelectedIndex -= 1;
            }

            membersDataGrid.SelectedIndex = currentSelectedIndex;
        }
        /// <summary>
        /// Handle the filter button click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnFilterButtonClick(object sender, RoutedEventArgs args)
        {
            MainWindowDataContext dataContext = (MainWindowDataContext)DataContext;

            dataContext.IsFilterActive = true;

            // Sort data and then search by name
            PropertyInfo filterProperty = (PropertyInfo)PropertySortComboBox.SelectedItem;
            MemberTab    tab            = (MemberTab)MemberTypeTabControl.SelectedItem;

            bool sortAscending = SortAscendingCheckbox.IsChecked != null && SortAscendingCheckbox.IsChecked.Value;

            // Local predicate function to facilitate order-by property
            object SortSelector(Member element) => filterProperty.GetValue(element, null);

            IEnumerable <Member> filterData = sortAscending ? tab.Data.OrderBy(SortSelector) : tab.Data.OrderByDescending(SortSelector);

            string nameQuery = SearchTextbox.Text.ToLower();

            if (!string.IsNullOrEmpty(nameQuery))
            {
                // Check if the first name, last name, first + last name, or last + first name contain the query string
                filterData = filterData.Where(element => element.FirstName.ToLower().Contains(nameQuery) ||
                                              element.LastName.ToLower().Contains(nameQuery) ||
                                              string.Join(" ", element.LastName, element.FirstName).ToLower().Contains(nameQuery) ||
                                              string.Join(" ", element.FirstName, element.LastName).ToLower().Contains(nameQuery));
            }

            DataGrid membersDataGrid = (DataGrid)MemberTypeTabControl.GetChildren().Find(control => control is DataGrid);

            membersDataGrid.ItemsSource = filterData;
        }
        /// <summary>
        /// Handle the clear filter button click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnClearFilterButtonClick(object sender, RoutedEventArgs args)
        {
            MainWindowDataContext dataContext = (MainWindowDataContext)DataContext;

            dataContext.IsFilterActive = false;

            MemberTab tab             = (MemberTab)MemberTypeTabControl.SelectedItem;
            DataGrid  membersDataGrid = (DataGrid)MemberTypeTabControl.GetChildren().Find(control => control is DataGrid);

            membersDataGrid.ItemsSource = tab.Data;
        }
        /// <summary>
        /// Handle the new member button click event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnNewMemberButton(object sender, RoutedEventArgs args)
        {
            Team      team      = (Team)TeamSelectionComboBox.SelectedItem;
            MemberTab memberTab = (MemberTab)MemberTypeTabControl.SelectedItem;

            Member newMember = (Member)Activator.CreateInstance(memberTab.MemberType);

            team.AddMember(memberTab.MemberType, newMember);

            // Find a child data-grid of the tab control
            DataGrid membersDataGrid = (DataGrid)MemberTypeTabControl.GetChildren().Find(control => control is DataGrid);

            membersDataGrid.SelectedItem = newMember;
            membersDataGrid.ScrollIntoView(newMember);
        }
        /// <summary>
        /// Handle the member tab control selection changed event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnMemberTabControlSelectionChanged(object sender, SelectionChangedEventArgs args)
        {
            if (!(args.Source is TabControl))
            {
                return;
            }

            MemberTab tab = (MemberTab)MemberTypeTabControl.SelectedItem;

            if (tab != null)
            {
                PropertySortComboBox.ItemsSource  = MemberTabControlContentTemplateSelector.GetMemberAttributes(tab.MemberType);
                PropertySortComboBox.SelectedItem = PropertySortComboBox.Items[0];
            }
            else
            {
                PropertySortComboBox.ItemsSource = null;
            }

            MainWindowDataContext dataContext = (MainWindowDataContext)DataContext;

            dataContext.IsFilterActive = false;
        }