[英]How to open a form in same window in WPF application
I am learning c# WPF application. 我正在学习c#WPF应用程序。
I have a menu which has a dropdown list. 我有一个菜单,其中有一个下拉列表。 In the dropdown there are 3 other items.
在下拉列表中还有3个其他项目。
Now on clicking an item i want to display the form in the same window. 现在单击一个项目我想在同一窗口中显示该表单。
What i did is that i have created a new wpf form and navigated it from the previous page. 我所做的是我创建了一个新的wpf表单,并从上一页导航它。
But now i want to open it in the same page itself. 但现在我想在同一页面打开它。
Please help 请帮忙
XAML: XAML:
<Grid>
<DockPanel Height="43" HorizontalAlignment="Stretch" Name="dockPanel1"
VerticalAlignment="Top">
<Menu Height="47" Name="menu1" Width="Auto" DockPanel.Dock="Top"
VerticalAlignment="Top" HorizontalAlignment="Stretch" >
<MenuItem Header="_Entry Form" >
<MenuItem Header="_Student Details" Name="studentDetails" Click="studentDetails_Click_1"/>
<MenuItem Header="_Faculty Details" Name="facultyDetails" />
<Separator/>
<MenuItem Header="E_xit" Name="exit" />
</MenuItem>
</Menu>
</DockPanel>
CS CS
private void studentDetails_Click_1(object sender, RoutedEventArgs e)
{
// to navigate to a new page
Student std = new Student();
this.Close();
std.Show();
}
Now i donot want to navigate just display the student page in the same window 现在我不想导航只在同一个窗口中显示学生页面
Firstly, you'll need to add XAML that represents the Student
class, probably a bunch of TextBoxes
, wrapped in some kind of container, like a Border
, Grid
, or StackPanel
, and set the Visibility
property of the container to Collapsed
. 首先,您需要添加代表
Student
类的XAML,可能是一堆TextBoxes
,包装在某种容器中,如Border
, Grid
或StackPanel
,并将容器的Visibility
属性设置为Collapsed
。
When the button is then clicked, you can populate the text boxes (or other UI elements) with the appropriate Student
parameters, then set the container's Visibility
property to Visible
. 单击该按钮后,可以使用相应的
Student
参数填充文本框(或其他UI元素),然后将容器的Visibility
属性设置为Visible
。
I would really recommend you check out the Model-View-ViewModel (MVVM) pattern, though. 我真的建议您查看Model-View-ViewModel(MVVM)模式。 There is a bit of a learning curve, but it's well worth the investment.
有一点学习曲线,但值得投资。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.