2

WPF window that have a content control with Prism region manager and region name. Prism region have a user control that injected to it. Window open and fully loaded, after reconnect with RDP, the window Prism region lost the injected view. I figure out that on RDP reconnecting the widow is updating layout and re render, loading event is firing and UpdateLayout as well.

Any idea ?

I already observe the following solution but it doesn’t helped on this one.

WPF: Prevent unload & load after RDP (dis)connect

<ContentControl x:Name="DetailRegion"    Grid.Row="1"
                        Visibility="{Binding IsAgentVisible,`enter code here`
                                             Converter={StaticResource BoolVisibilityConverter},
                                             ConverterParameter=Collapsed}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        Focusable="False"
                        Padding="5"
                        regions:RegionManager.RegionManager="{Binding CvaRegionManager,UpdateSourceTrigger=PropertyChanged}"
                        regions:RegionManager.RegionName="StandAloneCVAViewRegion" />
Denis Schaf
  • 2,478
  • 1
  • 8
  • 17
Tomer Trojman
  • 61
  • 1
  • 8

1 Answers1

0

When RDP reconnecting the control hosting the content control is recreated. I can solve the problem by creating the Prism region by c# code, thus I can handle the case of recreation of the control and check if Region already store a view.

 private void CvaControl_Loaded(object sender, RoutedEventArgs e)
        {                
            SetRegionManager(this.DetailRegion, "StandAloneCVAViewRegion");
        }

        void SetRegionManager(DependencyObject regionTarget, string regionName)
        {
            var cvaRegionManager = ((CvaApplicationViewModel) DataContext).CvaRegionManager;
            if (cvaRegionManager.Regions.ContainsRegionWithName("StandAloneCVAViewRegion"))
            {
                this.DetailRegion.Content = cvaRegionManager.Regions["StandAloneCVAViewRegion"].ActiveViews.First();
                return;
            }
            RegionManager.SetRegionName(regionTarget, regionName);
            RegionManager.SetRegionManager(regionTarget,cvaRegionManager);
        } 
Tomer Trojman
  • 61
  • 1
  • 8