1

I am in a situation where i try to create notification when i try to switch from one TabItem to another and i try to do so using LostFocus().

Actually my each TabItem consists of TextBlock and some data written on it. So the switching notification i try to achieve like this:

    StackPanel sp = new StackPanel() 
    { 
       Orientation = Orientation.Horizontal
    };
    sp.Children.Add(generateTextBlockContaini()); 
    TabItem tbi = new TabItem();
    tbi.Header = sp;
    tbi.LostFocus +=(o,e) =>
     {

         //MesssagePop up 
         MessageBox.Show("Hurrey tabItem changed");
     }; 

The problem arises are:

(1) It works fine but i need to click once on the textblock when i switch to another TabItem in order to popup this messagebox (because its focus is not set if i do not click). Is there any way to set focus of textblock in silverlight 5 ?

(2) Even if it is set it will call infinitely because i replaced textblock by textbox and i used Focus() and it was calling infinitely.

user3735822
  • 337
  • 2
  • 12

2 Answers2

0

Usually TabItems are used together with TabControls. This provides properties and events for changing tabs.

Silverlight tabchanged event - tabcontrol

Community
  • 1
  • 1
0

For your particular case you could use MouseLeave and MouseEnter events instead of LostFocus and GotFocus. Those events will fire without requiring the user to click on a control inside your TabItem.

Marius Bughiu
  • 997
  • 14
  • 32