0

I have a MainWindow with a ViewModel, when I press a button, a new SubWindow, with its onw ViewModel is opened, which recieves the "parent" ViewModel, like this:

    private AppViewModel vm;

    public void Show(AppViewModel vm)
    {
        this.vm = vm;
        this.DialogShown = true;
    }

When I close the SubWindow this method is called:

    public void Hide()
    {
        vm.IsFocused = true;
        this.DialogShown = false;
    }

But in my MainWindow my TextBox doesn't get focused...

This is my property:

 public bool IsFocused
    {
        get { return _isFocused; }
        set
        {
            if (value != _isFocused)
            {
                _isFocused = value;
                OnPropertyChanged("IsFocused");
            }
        }
    }

And this is my xaml:

<TextBox Focusable="True" AcceptsReturn="True" ext:FocusExtension.IsFocused="{Binding IsFocused, Mode=TwoWay}"  IsTabStop="False"/>

What am I doing wrong?

alface
  • 79
  • 2
  • 10
  • http://stackoverflow.com/a/1356781/891715 – Arie Oct 18 '16 at 14:10
  • 1
    what is `ext` in `ext:FocusExtension.IsFocused` ?? – Abin Oct 18 '16 at 15:06
  • You can't set focus to a non-visible object, so my best guess is it is trying to set focus when it's not visible, then making it visible afterwards. Try reversing the order of your `IsFocused` and `DialogShown` lines. Other than that, it might be something to do with how your dialog system is setup, or focus setup in your Controls... WPF has two types of focus. Any number of items can have Logical Focus, but only one item can have Keyboard Focus. You might need to add something to manually set Keyboard Focus back to your View when a Dialog gets hidden. – Rachel Oct 18 '16 at 15:24

0 Answers0