.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Focus in WPF Controls

Posted By:Diptimaya Patra       Posted Date: May 17, 2010    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  

Focus in WPF Controls. In this article we will see how we can manage Focus of specific controls in WPF.
 

Introduction

In this article we will see how we can manage Focus of specific controls in WPF. In some projects requirement some controls need not be focused, need to be focused all the time. We will see how to achieve that.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as FocusManagerWPF.

WPFFocusManager1.gif

Let's have a bunch of controls so that we can see the real Focus Manager working.

WPFFocusManager2.gif

As you see above I have some Container controls that holds multiple controls inside it.

Now Let's run the application and see how default Focus works.

WPFFocusManager3.gif

To go to the particular control we need to press TAB, and that's how we set focus on each control.

If you press TAB continuously, you will see that each control gets focused when we press tab in a cyclic manner, that is starting from Check Box 1 to the PasswordBox Control and it cycles continuously.

So we got to know that the default Focus Manager is Continuous.

Now we will see how we can restrict that.

WPFFocusManager4.gif

As you see above we have a Class called KeyBoardNavigation.

WPFFocusManager5.gif

As you see we have several properties that would help us for our tab/focus restriction.

Now choose TabNavigation.

WPFFocusManager6.gif

As you see above we have the following enums that we can use.

Let's see how Cycle will help us.

WPFFocusManager7.gif

You would see the Tab Navigation Cycles through the CheckBoxes.

Let's see how None will help.

WPFFocusManager8.gif

You would see the TAB key never focuses the CheckBoxes at all.

Let's see how Once will help us.

WPFFocusManager9.gif

You would see it focuses the first element when we press TAB and continues to other controls.

The other options such as Continue, Cycle and Local are same.

So in this article we experienced how we can take help of KeyboardTabnavigation to help us for managing our Focus on specific controls.

You can also  download sample project used in the above example.

Hope this article helps.

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend