6

I have a problem with a TabControl, a TextBox and a validation ToolTip.

Imagine having a TabControl with two TabItems. On the first item there is a simple TextBox. This TextBox Text property is bound to a string property of the UserControl itself with Mode=TwoWay and ValidatesOnExceptions=True. The setter of that Text property throws an exception whenever something is set.

The Resources section of the UserControl contains a new default style for the TextBox and the validation ToolTip (those styles and templates however are taken from the MSDN).

Now enter something into the TextBox and let the validation ToolTip appear:

enter image description here

Then change to the second tab. The validation ToolTip remains:

enter image description here

I have produced a VS solution containing a Silverlight application that demonstrates the issue. The VS solution zip archive is available here.

Has anyone had similar problems or even a solution for that issue?

Disclaimer: There is similar question here on StackOverflow with regard to Silverlight 4 which has been unanswered since about one and a half years. I already posted that question on silverlight.net but got no replies for several days.

Community
  • 1
  • 1
Spontifixus
  • 6,570
  • 9
  • 45
  • 63

2 Answers2

3

I think this is a bug of the TabControl-implementation. I've implemented the this behavior to fix this in our application:

public class TabControlFixBehavior: Behavior<TabControl>
{
    protected override void OnAttached()
    {
        AssociatedObject.SelectionChanged += AssociatedObjectOnSelectionChanged;
        base.OnAttached();
    }

    protected override void OnDetaching()
    {
        AssociatedObject.SelectionChanged -= AssociatedObjectOnSelectionChanged;

        base.OnDetaching();
    }

    private void AssociatedObjectOnSelectionChanged(object sender, SelectionChangedEventArgs args)
    {
        if (args.RemovedItems.Count > 0)
        {
            var oldTabItem = args.RemovedItems[0] as TabItem;
            if (oldTabItem != null)
            {
                var popups = VisualTreeHelper.GetOpenPopups();
                foreach (var popup in popups)
                {
                    var toolTip = popup.Child as ToolTip;
                    if (toolTip != null)
                    {
                        if (VisualTreeHelper.GetRoot(toolTip.PlacementTarget) == oldTabItem.Content)
                        {
                            popup.IsOpen = false;
                        }
                    }
                }
            }
        }
    }
}
Spontifixus
  • 6,570
  • 9
  • 45
  • 63
AndreyR
  • 294
  • 4
  • 15
0

the validation tooltip is an implicit feature in silverlight 5. Please clear the "UserControl.Resources" node in your "main page" usercontrol and you will have the expected behavior.

[EDIT] I did not read the end of your question, sorry :)

Blaise
  • 121
  • 5
  • Thanks for your reply, removing the resources indeed solves the issue, but is not an option in my case because I need these controls styled. I just included the default style from the MSDN in my example to prove that this problem is not being caused by my styles. – Spontifixus Jul 17 '12 at 08:23