Search code examples
silverlighttabcontrolsilverlight-5.0tabitem

TabItem contents disabled when selecting different tabs


We have an issue whereby when closing a shared control (within a child window) when a different tab, other than the first tab is selected, the contents of the tab are disabled are subsequently disabled when reloading the control. However, if you select a different tab and navigate back to the original tab, the contents are then enabled.

Disabled tab contents

Does anybody have an insight to what is causing the original disabling effect & a fix for this as I am struggling with this one?

XAML

 <customTab:CustomTabControl x:Name="ctcNoteTabControl" Margin="10"> 
    <customTab:CustomTabItem Header="Details">
        <Border Background="White" CornerRadius="10">
            ...
        </Border>
    </customTab:CustomTabItem>
    <customTab:CustomTabItem Header="Attachments / Email Alerts">
        <Border Background="White" CornerRadius="10">
            ...
        </Border>
    </customTab:CustomTabItem>
    <customTab:CustomTabItem Header="Assets" x:Name="ctiAssets">
        <Border Background="{StaticResource CurveBlockBackground}" CornerRadius="10" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2">
            ...
        </Border>
    </customTab:CustomTabItem>
</customTab:CustomTabControl>

C# - Custom class inheriting from TabControl

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ReACTSL.Control
{
    public class CustomTabControl : TabControl
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Home:
                case Key.End:
                    e.Handled = true;
                    break;
                default:
                    break;
            }

            base.OnKeyDown(e);
        }
    }
}

C# - Custom class inheriting from TabItem

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ReACTSL.Control
{
    public class CustomTabItem : TabItem
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Home:
                case Key.End:
                case Key.Left:
                case Key.Right:
                case Key.Up:
                case Key.Down:
                    e.Handled = true;
                    break;
                default:
                    break;
            }

            base.OnKeyDown(e);
        }
    }
}

Solution

  • I have found the answer and thankfully it is not a TabControl related problem.

    After further investigation, the problem only occurred upon clicking the Save button and not the Cancel or child windows close button. The only difference between these, apart from a service call to save the contents, is the use of the BusyIndicator control from the same System.Windows.Controls.dll for Silverlight 5 (SDK).

    This was being displayed whilst the service call was being executed

    busyIndicator.IsBusy = true;
    

    However it is was never being stopped from displaying once the service call had returned and the response had been processed. As the control is shared, this meant that the tab which was selected when the Save button was clicked, remained disabled, for some reason I am not sure about.

    I simply set the IsBusy property to false before closing the shared control and everything was enabled upon re-opening the shared control.

    busyIndicator.IsBusy = false;