How to autohide a toolwindow (MVVM)

Docking/MDI for WPF Forum

Posted 7 years ago by Michael Bayer
Version: 16.1.0633
Avatar

Hi,

following your MVVM samples I have a few toolwindows that are based on viewmodels. A toolwindow as a button Apply. If this button is pressed, I want to autohide the toolwindow, but

State = ToolWindowState.AutoHide
IsOpen = False

 doesn't work. The toolwindow stays open. How can I autohide it? I only find a solution to close a documentwindow in the samples.

Thank you

Michael

Comments (5)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

I'm not sure why it's not working in your particular scenario (maybe you didn't set up two way bindings properly with the tool window and your VM?), but if you add this code to the MainView.xaml.cs in our MvvmToolWindows sample, you can see it working when you focus a control in the docking area and press any key:

protected override void OnKeyDown(KeyEventArgs e) {
	base.OnKeyDown(e);

	var vm = (MainViewModel)this.DataContext;
	vm.ToolItems[0].State = Common.ToolItemState.AutoHide;
	vm.ToolItems[1].IsOpen = false;
}


Actipro Software Support

Posted 7 years ago by Michael Bayer
Avatar

Hi,

I was unclear. What I want is: when clicking an Apply-Button within a toolwindow that has State=AutoHide the toolwindow shall be closed without removing it from layout (auto-hidden)

This works:

  • open the toolwindow, click the pin with the mouse to dock the toolwindow and press Apply: toolwindow is auto-hidden (1)
  • open the toolwindow and click Apply: the toolwindow is docked (2)
  • open the toolwindow and click Apply: the toolwindow becomes a document (3)

Code in viewmodel for Apply functionality:

(1) State=ToolWindow.AutoHide

(2) State=ToolWindow.Docked

(3) State=ToolWindow.Document

 

This doesn't work:

  • open the toolwindow and click Apply: the toolwindow should be auto-hidden (1)

(1) State=ToolWindow.AutoHide

 

How can I induce the toolwindow to auto-hide itself when pressing the Apply button? I tried IsOpen/IsActive/IsSeleted=False, but this doesn't work.

Thank you

Michael

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

If I understand correctly, the tool window is already in auto-hide state but its flyout is open and you simply want to have the flyout slide back so only the tab is visible, right?

If you want to do this purely in MVVM, you would need to get focus to move to another docking window.  You could probably set IsActive to true on any document or tool window, and I believe that would work.

Or if you have access to the tool window itself that you are talking about, you could simply do:

toolWindow.DockHost.CloseAutoHidePopup(false, true);


Actipro Software Support

Posted 7 years ago by Michael Bayer
Avatar

Hi,

you described it perfectly. Setting IsActive on another docking window works. A simple solution - I didn't see the forest for the trees.

Nonetheless: I've build my application following your mvvm samples, so the toolwindows and documentwindows based on a class, that inherits from ObservableObjectBase.

How can I get access to the toolwindowcontainer and the toolwindows/documentwindows itself to use their properties and methods like you showed above?

Thank you very much.

Michael

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

It's up to you to determine how to structure your view models and if you want to have the maintain a reference to other view model objects.  For instance if you based on our samples, you could have your tool item view models maintain a ref to the MainViewModel.  Then that would let you get to all the tool view models.

Or alternatively, your Apply button is likely in a UserControl view, whose parent/ancestor in the visual tree is probably a ToolWindow.  You can find it using our VisualTreeHelperExtended.GetAncestor<ToolWindow>(this) method call.  Add a Click handler to that view and in response, and find the ancestor ToolWindow using GetAncestor, then execute the C# I had in my last reply.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.