This project has moved. For the latest updates, please go here.

Create modal ChildWindow in Code and Display it

Jul 20, 2015 at 4:57 PM
Is it possible to create a childWindow and display it in code?
My code is not throwing errors but I'm not seeing anything.
        var msg = new ChildWindow();

        msg.Caption = caption;
        msg.Background = Brushes.Black;
        msg.Foreground = Brushes.Yellow;
        msg.CaptionShadowBrush = Brushes.Black;
        msg.CaptionForeground = Brushes.Yellow;
        msg.WindowBackground = Brushes.Black;
        msg.WindowInactiveBackground = Brushes.Black;
        msg.IsModal = true;
        msg.Left = 175;
        msg.Top = 25;

        msg.Width = 200;
        msg.Height = 200;
        msg.WindowBorderThickness = new Thickness(0);
        msg.Show();
Jul 24, 2015 at 10:48 PM
Edited Jul 24, 2015 at 10:49 PM
Did you try adding anything to it? Try insert something like this into your code:
Label displayText = new Label();
displayText.Content = caption;
StackPanel sp = new StackPanel();
sp.Children.Add(displayText);
msg.Content = sp;
Developer
Jul 27, 2015 at 3:07 PM
Hi,

Make sure you add the "msg" to the VisualTree.
For example, if your XAML looks like this :
<StackPanel x:Name="stack">
      <xctk:TimePicker Width="150"
                       Height="22" />
      <Button Content="TEST"
              Click="Button_Click_1" />
   </StackPanel>
Then, when creating the ChildWindow, add this :
stack.Children.Add( msg );