How to tell when a ToolWindow is visible from its DataContext (ViewModel)?

Docking/MDI for WPF Forum

Posted 4 years ago by Eric P
Version: 15.1.0623
Avatar

When I have a ViewModel as the DataContext for a ToolWindow how can I tell when the ToolWindow becomes visible (visibility changed)? The ToolWindow has an IsOpen Boolean property and by using an attached behavior I can add an IsActive but these two properties are not enough to let the ViewModel know all the states. A ToolWindow can be open but not active or visible because there could be other ToolWindows in the same container and only one can be visible at one time. Also just because the ToolWindow is visible does not mean its active.

So how can my ViewModel know when the visibility of its ToolWindow changes?

Comments (9)

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

Hi Eric,

Check this blog post out:

http://blog.actiprosoftware.com/post/2015/08/24/DockingMDI-vNext-MVVM-Property-Improvements

In the work we're doing or vNext, we've really improved the data-binding features.  We now have properties like IsOpen, IsSelected, IsActive, and State.  And all of these are now settable.  So you'll be able to use those to let your VM know what's going on and alter things.

IsOpen and IsSelected are in the current version as settable too.  State is there as well but it's read-only.


Actipro Software Support

Posted 4 years ago by Eric P
Avatar

Thanks for the reply. Yes I see the State (read-only) property now. So adding a setter for this property would be great but I think your going to have to add another value to the enum as well. Currently the enum contains Docked, Floating, Document, and AutoHide. Don't you also need a Hidden value? This is the case where the DockingWindow does have a parent container but its just not visible. Its been created bu not visible at this time.

So can I get my hands on a trial version of the vNext/docking API?

Posted 4 years ago by Eric P
Avatar

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

Hi Eric,

As a side note, in vNext there is no more Floating state.  We had to do this since the windows are really still in Docked or Document states, but in a floating DockHost instead.  vNext allows full MDI scenarios in floating windows, whereas the current version does not.

We shoudn't need a Hidden value for State.  What you are describing is the same as IsOpen=true and IsSelected=false.  The State needs to persist so that if a window is closed, it knows what state to restore back into when it is reopened.

As for the vNext beta, it's not available yet.  Please watch our blog for a notification of when it's ready.  We'll definitely want some testers when it's ready.


Actipro Software Support

Posted 4 years ago by Eric P
Avatar

We are looking forward to trying out the beta for vNext but for now is there a way to tell when a DockingWindow changes visibility from a ViewModel? I do not mind using an attached behavior but I do not see any event that first when the visibility of the DockingWindow changes. Is that true?

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

Hi Eric,

Yes, the IsOpen property tells you if it's open in the layout or not.  If it's IsOpen and IsSelected, then it's visible in the tabs.

The DockSite.WindowOpened and WindowClosed events tell you when a window is added to (opened) or removed from (closed) the layout.


Actipro Software Support

Posted 4 years ago by John Smith
Avatar

Hi,

we have few ToolWindows in ToolWindowContainer. By setting IsOpen and IsSelected for only one TooloWindow get all another Windows the same state. how can we solve this problem?

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

Do you mean that you want to open the first one and then open the rest as "attached" to it in the same tool window container? 

If so, in the 2015.1 version you could open the first one and then call secondTW.Dock(firstTW, Direction.Content) to attach to it and repeat for others.  Then you can call Activate() on the one that you want to be selected.

In the upcoming 2016.1 version, you can give each window the same WindowGroupName and then set IsOpen on all of them and IsActive on the one you want focused/selected.


Actipro Software Support

Posted 4 years ago by Eric P
Avatar

So I found a different way to achieve this with XAML and a Command.

<userControl ....
             xmlns:i="clr-namespace:System.Windows.Interactifity;assembly=System.Windows.Interactivity"
             ...>

  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
      <i:InvokeCommandAction Command="{Binding InitializeCommand}" />
    </i:EventTrigger?
  </i:Interaction.Triggers>

  ...

</UserControl>

This UserControl is the View for a specific ToolWindow. Each time this ToolWindow becomes visible it will fire the InitializeCommand in my ViewModel. In the method for this command I keep track of two Booleans called IsInitialized and IsInitializing so I know if the ViewModel has already been initialized or if it’s currently being initialized. I like this approach much better because the method bound to the command can be an asyc method. We are also using the DelegateCommand from Prism. Thus my command is defined like the following.

InitializeCommand = DelegateCommand.FromAsyncHandler(DoInitializeAsync);

private async Task DoInitializeAsync(){
  ...
}

This is not exactly what the latest comment was about but it does address the original question. I hope this helps someone else in the future.

Thanks,

   -eric

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.