Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF New Window with content

Tags:

c#

wpf

I want create a new Window beside an existing main Windwoe with a scrollable Textbox.

I'm pressing in my main Window on a button "Open New Window" and then it should open a new Window with a scrollable Textbox.

inside form2

In WPF you can drag drop elements in the main Window but cant do that for a new window. So I thought it is only possible when you create a new window in the MainWindow.xaml.cs

I was able to create a new Window trough:

private void btnConnect_Click(object sender, RoutedEventArgs 
 {
    Form form2 = new Form();
    //Do intergreate TextBox with scrollbar in form2

    form2.Show();

 }

and now I want a Textbox

But how can I do that in C# or WPF?

Thx

like image 737
user2261524 Avatar asked Dec 05 '22 11:12

user2261524


1 Answers

well... you can create a new Window and load into this Windows.Content a UserControl wich you createt in a new XAML. Example:

NewXamlUserControl ui = new NewXamlUserControl();
MainWindow newWindow = new MainWindow();
newWindow.Content = ui;
newWindow.Show();

the Xaml is could be like this

<UserControl x:Class="Projekt"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       x:Name="newXamlUserControl"      
        Height="300" Width="300">

    <Grid>

        <TextBox Text = ..../>

    </Grid>
</UserControl>
like image 72
dennis schütz Avatar answered Dec 18 '22 19:12

dennis schütz