PopupContent not updated when changing tabs in tabbed application

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 5 years ago by Justin Klein
Version: 19.1.0680
Platform: .NET 4.5
Environment: Windows 10 (64-bit)

Consider a tabbed multi-document application, were the currently active document is ActiveDocViewModel.  I've got a ToolWindow like:

<actidock:ToolWindow Title="3D" x:Name="Panel3D" >
    <local:Panel3D DataContext="{Binding ElementName=dockSite, Path=DataContext.ActiveDocViewModel}" />

In Panel3D, there's a listbox like:

<ListBox SelectionMode="Multiple" ItemsSource="{Binding SlicesList}" >
   <TextBlock Text="{Binding Name}"/>
  <Style TargetType="ListBoxItem">
   <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}"/>

Everything above works as expected: the listbox shows the items in the SlicesList property, and tabs are switched, SlicesList is updated with the SlicesList property for the current document.  However, if I simply wrap the ListBox in a PopupButton:

<actishared:PopupButton Content="Select" DisplayMode="Merged">
   <!--...Same as above...-->

Suddenly, changing tabs no longer updates the SlicesList (all tabs show the same list of slices, belonging to the 1st tab).  Why would wrapping the ListBox in a PopupButton break the binding in this way?

[Modified 5 years ago]

Comments (2)

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

Hi Justin,

Since a ContentPresenter is used as a child of the Popup that is dynamically created for the PopupButton, the DataContext no longer inherits at that point.  The PopupButton.PopupContent is used as the ContentPresenter.Content, and similar with the PopupContentTemplate being used as the ContentTemplate.

You would probably need to put a DataContext property Binding on your ListBox to specifically reference another element, like the PopupButton, and pass its DataContext along that way.

Actipro Software Support

Posted 5 years ago by Justin Klein

Aha - perfect, that does it, thanks!

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

Add Comment

Please log in to a validated account to post comments.