开发者

Preventing user from tabbing outside of Frame

In my WPF application, I have a page which contains various buttons and a frame. Inside this frame is a number of textboxes.

On start, I set the focus to the first textbox inside my frame. Is there any way I can ensure that Tab cycles just the elements within t开发者_JAVA技巧he frame, and doesn't jump outside to the parent page?

Thank you in advance.


set IsTabStop=false for controls outside the frame


To fix this, I set

KeyboardNavigation.TabNavigation="Cycle"

on the Frame.


tabstop will work.

now my alternative solution - just assumption: first element inside ur frame has tabindex equal to 5, last element inside frame has tabindex equal to 9. take the element that has maximum tabindex within the frame scope (i.e. according to assumption element with tabindex 9). on PreviewKeyDown event write the following code:

private void frames_max_tabindex_element_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyValue == 9 )
            element_that_has_tabindex_equal_to_frames_min_tab_index_minus_1.Focus();
        }

brief expl. (using assumtions to demonstrate idea) when focus is on the element of frame with tabindex 9, key down on tab will fire the PreviewKeyDown event. inside the method u are setting focus to the element that has tabindex equal to 4. and after tab key is released windows will set focus to the next tabindex i.e. to the element with tabindex equal to 5. so from tabindex = 9 u are jumping to the element with tabindex = 5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜