WPF 带有内容的新窗口 [英] WPF New Window with content
问题描述
我想在现有的主 Windwoe 旁边创建一个带有可滚动文本框的新窗口.
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.
在form2
在 WPF 中,您可以在主窗口中拖放元素,但不能在新窗口中执行此操作.所以我认为只有在 MainWindow.xaml.cs 中创建一个新窗口时才有可能
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();
}
现在我想要一个文本框
但是我如何在 C# 或 WPF 中做到这一点?
But how can I do that in C# or WPF?
谢谢
推荐答案
好吧...您可以创建一个新窗口并将其加载到此 Windows.Content 一个您在新 XAML 中创建的 UserControl.示例:
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();
Xaml 可能是这样的
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>
这篇关于WPF 带有内容的新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!