How can I prevent tabbing to a UserControl?

纵饮孤独 提交于 2019-11-30 08:22:51

问题


I have a custom Popup that overlays part of my screen. When it is open, I want to disable tabbing into the UserControl behind it. I do not want to use the IsEnabled property because I do not want to gray out all the controls.

Is there another property that does the same thing? IsTabStop only prevents the tab from stopping on the UserControl itself, not it's children, and IsFocusable isn't a valid property for a UserControl.


回答1:


Use the KeyboardNavigation.TabNavigation Attached Property with KeyboardNavigationMode.None on your container control.

KeyboardNavigation.TabNavigation="None"



回答2:


You can bind IsTabStop on the child controls to IsTabStop on the UserControl.

That way, you only have to set it once.




回答3:


You could write an attached property that you would set in the top element.
That attached property would recursively set IsTabStop to false in all the child elements.

Let me know if you need any help getting this to work.




回答4:


Just bind that property to the user control.

    <UserControl x:Class="PDV.UserControls.InputField"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 // etc... then:                     
                 x:Name="Root" KeyboardNavigation.TabNavigation="Local" >

        <Grid>
           <TextBox Name="textBox"  
                TabIndex="{Binding Path=TabIndex, ElementName=Root}" 
                IsTabStop="{Binding Path=IsTabStop, ElementName=Root}"  />                
        </Grid>
    </UserControl>


来源:https://stackoverflow.com/questions/7745361/how-can-i-prevent-tabbing-to-a-usercontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!