问题描述:

I am learning c# WPF application.

I have a menu which has a dropdown list. In the dropdown there are 3 other items.

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.

But now i want to open it in the same page itself.

Please help

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

 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.

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.

I would really recommend you check out the Model-View-ViewModel (MVVM) pattern, though. There is a bit of a learning curve, but it's well worth the investment.

相关阅读:
Top