弹出窗口弹出时,在弹出窗口中创建新的UserControl

时间:2011-06-16 17:47:57

标签: wpf vb.net user-controls popup

我有一个usercontrol,当用户从列表框中选择一个项目时,该弹出窗口会显示另一个用户控件。 当父级初始化时,所有用户控件都会初始化。

    <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>

代码背后:

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

问题是observablecollection中的数据永远不会从我查看的第一条记录发生变化。我也试过了

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

它只保留原始数据。 我真的很想每次都重新焕发活力,每次都有一个新的网站。

1 个答案:

答案 0 :(得分:0)

更改模板,使cCCLF不属于它。而是用&lt; Grid x:Name =“cCCLFGrid”/&gt;替换它。在你的代码中,当你想要创建一个新的cCCLF控件时,调用cCCLFGrid.Children.Clear,创建一个新的cCCLF,然后调用你刚刚创建的cCCLFGrid.Children.Add(cCCLF)。这保证了旧的和新的cCCLF的删除。