简体   繁体   English

在 wpf 的同一网格中的用户控件之间切换

[英]Switch between usercontrol in same grid in wpf

Hy guys please help.请大家帮忙。 I'm working in WPF program.我在 WPF 程序中工作。 I have a grid named body_grid where I display my usercontrols in MainWindow.我有一个名为 body_grid 的网格,我在 MainWindow 中显示我的用户控件。

My problem is that I can not switch between usercontrol in parent grid.我的问题是我无法在父网格中的用户控件之间切换。

Eg usercontrolA is displayed in body_grid with button.例如 usercontrolA 用按钮显示在 body_grid 中。

Now a usercontrolA button must remove usercontrolA in body_grid and display usercontrolB.现在 usercontrolA 按钮必须删除 body_grid 中的 usercontrolA 并显示 usercontrolB。

How can I do that please help我该怎么做请帮忙

This can be implemented using Visibility property.这可以使用 Visibility 属性来实现。 If you are not using MVVM patern, code below shows a example of what you are trying to accomplish:如果您没有使用 MVVM 模式,下面的代码显示了您尝试完成的示例:

private void Button_Click(object sender, RoutedEventArgs e)
{
    userControlB.Visibility = Visibility.Visible; 
    userControlA.Visibility = Visibility.Collapsed;        
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM