简体   繁体   English

如何从主窗口在WPF中调用用户控件?

[英]How do i call user control in WPF from main window?

lately i'm working on WPF UserControl ,i'm kind first time using UserControl after WPF window. 最近我正在使用WPF UserControl ,这是我第一次在WPF窗口之后使用UserControl I have created WPF Application, it has Window called " MainWindow ". 我创建了WPF应用程序,它具有名为“ MainWindow ”的窗口。 MAinWindow have Button named ' Technology '. MAinWindow具有名为“ Technology ”的按钮 I have also created UserControl named ' TechnologyUserControl '.I want to show ' TechnologyUserControl ' after clicking on button ' Technology '. 我也创建UserControl名为“ TechnologyUserControl ”。我想展示“ TechnologyUserControl点击按钮”后“ Technology ”。 Can anybody help me .. Thanks.. 谁能帮我..谢谢..

I was going to downvote you or comment: 'What have you tried?', but then again: 我本来要对您投反对票或评论:“您尝试了什么?”,然后再次:

You need to instantiate the UserControl, set its DataContext and add it to a parent view. 您需要实例化UserControl,设置其DataContext并将其添加到父视图。 You can do this either with markup (XAML), or in code. 您可以使用标记(XAML)或代码进行此操作。

如果您的TechnologyUserControl首先设置为“ 隐藏” ,请在Technology上创建一个click事件并将其放置在其中:

TechnologyUserControl.Visibility = System.Windows.Visibility.Visible;

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

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