简体   繁体   English

如何在WPF应用程序中打开同一窗口中的表单

[英]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 ,包装在某种容器中,如BorderGridStackPanel ,并将容器的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.

相关问题 我如何在同一个pragrom /应用程序中重新打开WPF窗口? - How I re-open WPF window in the same pragrom/application? 如何从另一个应用程序打开WPF窗口 - How to Open a WPF Window from Another Application 如何从wpf应用程序动态打开/关闭控制台窗口? - How to open/close console window dynamically from a wpf application? 如何在C#中的同一窗口中打开新表单窗口? - How to open a new form window within same window in C#? 如何确定WPF窗口是否打开? - How to determine if WPF window is open? 如何防止我的程序打开同一个窗口 Form 两次 - how to prevent my program to open the same window Form twice 切换到 MVVM 架构中的任何其他应用程序后,如何在 WPF 中的主窗口前打开一个新窗口? - How to bring a new window open in front of Main Window in WPF after switching to any other application in MVVM architecture? 如何创建单个实例WPF应用程序,在尝试打开另一个实例时还原打开的窗口? - How to create single instance WPF Application that restores the open window when an attempt is made to open another instance? 在 WPF 应用程序的 window 面板中显示表单 - Displaying a form in a window panel in WPF application 从 WinForms 打开 WPF 窗口并使用 WPF 应用程序链接表单应用程序 - Open a WPF Window from WinForms & link form app with WPF app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM