Automatic tab in Silverlight 3

I need to be able to automatically tab from a control to the “next control” in an SL3 application. For example, the TextBox is limited to 3 characters-when typing the third character, the focus It should automatically move to the next control on the form (my actual usage is slightly different, but this example is sufficient).

However, since SL automatically determines the label sequence, except for reverse engineering/ Copying the logic of Silverlight to determine which control in the visual tree should be outside the next control that has the focus, there seems to be no way to do this.

Has anyone implemented this?

I’m looking for a fairly general solution – but I’ve been able to do some fairly specific things – Basically it uses VisualTreeHelper to find the child of the same parent item as the control next to me, and set the focus to that.

This is a better way than passing all my controls ( This is a rather large LOB application) a more suitable solution, and configure the “next” control for each control.

This is my code in case it helps others. (VisualTreeeHelperUtil Is a class of my own, it adds some utilities to VisualTreeHelper)

public static void TabNext(DependencyObject parentElement, Control fromControl)
{
var children = VisualTreeHelperUtil.FindChildren(parentElement).
Where(c => c.IsEnabled && c.IsTabStop && c.Visibility == Visibility.Visible).
ToList();

if (children.Contains(fromControl))
{
var thisIndex = children.IndexOf(fromControl);
var targetIndex = thisIndex + 1;
if (children.Count> targetIndex)
{
var targetChild = children[targetIndex];
fromControl.Dispatcher.BeginInvoke(() =>
{
targetChild.Focus();
var txt = targetChild as TextBox;
if (txt != null)
{
txt.SelectAll();
}
});
}
}
}

I need to be able to automatically tab from a control to an SL3 application “Next control”. For example, the TextBox is limited to 3 characters-when typing the 3rd character, the focus should automatically move to the next control on the form (my actual usage is slightly different, but this example is sufficient)

However, since SL automatically determines the label sequence, there does not seem to be any other than reverse engineering/copying Silverlight’s logic to determine which control in the visual tree should be the next control to gain focus Ways to do this.

Has anyone achieved this before?

I am looking for a fairly general solution-but I have been able to do some fairly specific things-basically it uses VisualTreeHelper to find the The next control is a child of the same parent item, and set the focus to that.

This is a better fit than through all my controls (this is a fairly large LOB application) Solution and configure the “next” control for each control.

This is my code in case it helps others. (VisualTreeeHelperUtil is a class of my own, it adds for VisualTreeHelper Some utilities)

public static void TabNext(DependencyObject parentElement, Control fromControl)
{
var children = VisualTreeHelperUtil.FindChildren(parentElement) .
Where(c => c.IsEnabled && c.IsTabStop && c.Visibility == Visibility.Visible).
ToList();

if (children.Contains( fromControl))
{
var thisIndex = children.IndexOf(fromControl);
var targetIndex = thisIndex + 1;
if (children.Count> targetIndex)
{
var targetChild = children[targetIndex];
fromControl.Dispatcher.BeginInvoke(() =>
{
targetChild.Focus();
va r txt = targetChild as TextBox;
if (txt != null)
{
txt.SelectAll();
}
});
}
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4009 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.