ChildWindow in a UserControl

May 14, 2013 at 10:18 AM
In my application I have a UserControl which contains a ChildWindow.
When I open the ChildWindow it gets centered inside the UserControl and can only moved inside it because it is part of its visual tree as far as I understood it.

But I want it to be centered and able to be moved over the whole application and not just the UserControl. Is there a way to accomplish this without implementing it outside of the UserControl?
Coordinator
May 14, 2013 at 3:54 PM
try this:
<UserControl>
  <Grid>
    <Grid>
      ... Put your "screen" here
    </Grid>
    <!-- This grid is "overlaped" over the "screen" content -->
    <Grid>
      <xctk:ChildWindow .../>
    </Grid>
  </Grid>
</UserControl>
May 16, 2013 at 9:05 AM
Edited May 16, 2013 at 9:50 AM
Sorry but I don't understand what you meant with <!-- This grid is "overlaped" over the "screen" content -->

I also tried to add the Popup to Grid of the Main Application Window in the contructor of my UserControl but this way it doesn't get displayed when I set its WindowState to Open
public MyCTor()
{
     InitializeComponent();
     (Application.Current.MainWindow as MainWindow).RootGrid.Children.Add(popup);
}

        new public object DataContext
        {
            get
            {
                return base.DataContext;
            }
            set
            {
                base.DataContext = value;
                if (DataContext != null)
                {
                    popup.DataContext = DataContext;
                }
            }
        }
Coordinator
May 16, 2013 at 1:21 PM
<!-- This is the main window -->
<Window>
   <!-- This is the "Top Grid" Cover the entire window-->
  <Grid  HorizontalAlignement="Stretch" VerticalAlignement="Stretch">

    <!-- Grid #1. Cover entirely "Top Grid" -->
    <Grid HorizontalAlignement="Stretch" VerticalAlignement="Stretch">
       .... some content
       <YourUserControl />
      ... Some other content
    </Grid>

    <!-- Grid #2. Cover entirely "Top Grid", again, like Grid #1
            "TopGrid" will overlapping Grid #2 over Grid #1 because it has no "Grid.Row" and "Grid.Column" values set.
             Just like Grid #1. -->
    <Grid  HorizontalAlignement="Stretch" VerticalAlignement="Stretch">
      <xctk:ChildWindow .../>
    </Grid>
  </Grid>
</Window>
May 16, 2013 at 3:40 PM
Yeah but that doesn't help because the UserControl contains the ChildWindow, its a logical part of it. So implementing it outside of it would be very strange.