How do you display a custom UserControl as a dialog?

后端 未结 7 1504
孤街浪徒
孤街浪徒 2020-12-07 15:45

How do you display a custom UserControl as a dialog in C#/WPF (.NET 3.5)?

7条回答
  •  独厮守ぢ
    2020-12-07 15:55

    If the answer by 'sixlettervariables' is modified as so, it works

    private void button1_Click ( object sender, RoutedEventArgs e )                  
    {
        Window window = new Window
        {
            Title = "My User Control Dialog",
            Content = new UserControl ( ),
            Height = 200,  // just added to have a smaller control (Window)
            Width = 240
        };
    
        window.ShowDialog ( );
    }
    

提交回复
热议问题