44

I want to add a WPF Input Box in my Project in C#. I got a WinForm one from InputBox in C# but it has Winform look and feel. So i was recreating it in WPF. I have created all the controls (Label, Button, Textbox) but i am unable to add them to my window.

static Window winInputDialog

The Window is showing through ShowDialog but without controls.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208

1 Answers1

90

There are two ways to get controls in your window:

  1. Do the whole designing stuff in the Designer of VisualStudio
  2. Add the controls by code. Here is a short, simple sample of creating a window and putting controls in it:

    var window = new Window();
    var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
    stackPanel.Children.Add(new Label { Content = "Label" });
    stackPanel.Children.Add(new Button { Content = "Button" });
    window.Content = stackPanel;
    
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
Fischermaen
  • 12,238
  • 2
  • 39
  • 56