PopupContent not updated when changing tabs in tabbed application

WPF Studio, Themes, and Shared Library for WPF Forum

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

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}" />
</actidock:ToolWindow>

In Panel3D, there's a listbox like:

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

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">
 <actishared:PopupButton.PopupContent>
  <ListBox>
   <!--...Same as above...-->
  </ListBox>
 </actishared:PopupButton.PopupContent>
</actishared:PopupButton>

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 7 months ago]

Comments (2)

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

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 7 months ago by Justin Klein
Avatar

Aha - perfect, that does it, thanks!

The latest build of this product (v2019.1 build 0683) 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.