I have a usercontrol that has a popup that displays another usercontrol when the user selects an item from a listbox.
When the parent initializes, all the usercontrols initialize.
<Popup x:Name="PopContactLogs" Width="670" StaysOpen="True" AllowsTransparency="True" PopupAnimation="Fade" PlacementTarget="{Binding ElementName=PageCustomerHome}" Placement="Center">
<Border CornerRadius="5" BorderBrush="DimGray" BorderThickness="2" Background="White">
<StackPanel>
<DockPanel Width="1180" Background="Gray">
<TextBlock Text="Customer Contact Logs" FontWeight="Bold" HorizontalAlignment="Center" />
<Button Name="cmdContactLogsClose" Content="X" Width="20" Foreground="Gainsboro" DockPanel.Dock="Right" />
</DockPanel>
<l:cCustomerContactLogFull x:Name="cCCLF" />
</StackPanel>
</Border>
</Popup>
Code behind:
Private Sub lstContactLogs_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles lstContactLogs.MouseDoubleClick
cCCLF = New Tracks.cCustomerContactLogFull(CustomerID, sender.selecteditem)
PopContactLogs.IsOpen = True
End Sub
The problem is that the data in the observablecollection never changes from the first record that I view. I’ve also tried
Private Sub lstContactLogs_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles lstContactLogs.MouseDoubleClick
cCCLF.CustomerID = CustomerID
cCCLF.ContactLog = sender.selecteditem
PopContactLogs.IsOpen = True
End Sub
and it just keeps the original data in there.
I’d really like to just reinitalize it every time and basically have a new webpart each time.
Change your template so that cCCLF isn’t part of it. Instead, replace it with a <Grid x:Name=”cCCLFGrid”/>. In your code behind, when you want to create a new cCCLF control, call cCCLFGrid.Children.Clear, create a new cCCLF, then call cCCLFGrid.Children.Add(cCCLF) that you just created. That guarantees the removal of the old and addition of the new cCCLF.