Search code examples
wpfmvvmchildwindow

MVVM-Block Tab key in WPF


I am working in WPF with MVVM. I implemented WPF Extended Toolkit and I use ChildWindow, when I open the ChildWindow the property IsModal is enabled. But this property does not block navigating with Tab.

I need block the navigating with Tab when the ChildWindos is open.

I tried with Focusable property but does not serve.


Solution

  • I understand your issue is with the tab in the background when show the ChildWindow.

    You should try modifying the property KeyboardNavigation.TabNavigation of de Window.

    If you use MVVM pattern do something like this in the XAML:

    <Window
    KeyboardNavigation.TabNavigation="{Binding TabNavigationMode}"
    >
    

    In the ViewModel:

    private KeyboardNavigationMode _tabNavigationMode;
    public KeyboardNavigationMode TabNavigationMode
    {
      get { return _tabNavigationMode; }
      set { _tabNavigationMode = value; RaisePropertyChanged("TabNavigationMode");
    }
    

    And create a Method like this that is invoked when you open and close the Child Window

    public void IsTabNavigationEnable(bool isEnable)
    {
        if (isEnable) TabNavigationMode = KeyboardNavigationMode.Contained;
        else TabNavigationMode = KeyboardNavigationMode.None;
    }
    

    I tried it and it works fine. The tab is disabled in the background but not in the ChildWindow.