1

I am working in silverlight and i am not able to set focus of textblock whereas i found the way to do for textbox (using Focus()) but not textblock.

Could some one please let me help in setting the focus of text block below (Silverlight 5)? :

TextBlock tb = new TextBlock();
user3735822
  • 337
  • 2
  • 12
  • `TextBlock` is no `Control`, therefore it cannot have focus. What do you want to accomplish? – Martin Jul 22 '14 at 12:41
  • @Martin see teh question . what i wam tryint to accomplish : http://stackoverflow.com/questions/24868119/how-to-notify-the-tabitem-switching-in-c-if-there-are-many-tabitems?noredirect=1#comment38658019_24868119 WHERE PEOPLE MARK IT DUplicate(without even reading it) – user3735822 Jul 22 '14 at 12:58
  • Your other question actually is a duplicate, you can easily use the [SelectionChanged](http://msdn.microsoft.com/en-us/library/system.windows.controls.tabcontrol.selectionchanged%28v=vs.95%29.aspx) event. The `TabControl` offers it and you can check for pending user changes and prompt the user from within the event handler whenever the user switches tabs. BTW: why do you create a new account every other week? – Martin Jul 22 '14 at 13:29

1 Answers1

1

if its a out of browser application,

    if (App.current.IsRunningOutOfBrowser)
    {
        tb.Focus();
    }
    else
    {
        System.Windows.Browser.HtmlPage.Plugin.Focus();
        tb.Focus();
    }
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • But ia m not running on browser my silverligth application and it do not recognize .Plugin.Focus(); – user3735822 Jul 22 '14 at 11:41
  • This works "using System.Windows.Browser.HtmlPage;" but this not : "System.Windows.Browser.HtmlPage.Plugin.Focus();" – user3735822 Jul 22 '14 at 11:42
  • I added " System.Windows.Browser.HtmlPage.Plugin.Focus(); TextBlock tb = new TextBlock(); tb.Focus();" atthe top of progaram i included :"using System.Windows.Browser.HtmlPage;" BUT "tb.Focus();" gives error this Focus is not recognized. – user3735822 Jul 22 '14 at 11:48
  • No.. Focus() is not working. tb do not contain any definition of Focus(). But this is not Webbrowser wpplication of Silverlight. I have my output on a window (not on browser). Is it due to that ? – user3735822 Jul 22 '14 at 11:52
  • @user3735822 check modified answer – Sajeetharan Jul 22 '14 at 11:54
  • No it do not work. In the secnd part it do not recogize Dispatcher and Focus both. – user3735822 Jul 22 '14 at 11:56
  • warning :The bridge DOM / scripting is disabled (corresponding to: System.Windows.Browser.HtmlPage.Plugin.Focus();) BUT I IF CONDITION IS " if(Application.Current.IsRunningOutOfBrowser)" because i am running out of browser. – user3735822 Jul 22 '14 at 12:03
  • Did you found any way to do so ? – user3735822 Jul 22 '14 at 12:07
  • @user3735822 Check modified answer, this how you generally do – Sajeetharan Jul 22 '14 at 12:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57755/discussion-between-sajeetharan-and-user3735822). – Sajeetharan Jul 22 '14 at 12:22