WPF和用户控制 [英] WPF and User control

查看:78
本文介绍了WPF和用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个选项卡项和一个用户控件.我想在运行时将用户控件添加到选项卡项吗?
有人可以帮我吗?

Hi guys,

I have a tab item and a user control. I want to add the user control to tab item at runtime?
Any one can help me in doing that?

推荐答案

只需实例化它,并将其添加到父容器的Children集合中即可.假设您在TabItem中有一个名为"LayoutRoot"的网格:

Just instantiate it and add it to the Children collection of the parent container. Assuming you have a grid in the TabItem called "LayoutRoot":

MyControl ctrl = new MyControl();
this.TabItem.LayoutRoot.Children.Add(ctrl);


您可以在运行时使用给定的代码添加用户控件
You can add user control at run time by using given code
UserControl1 obj = new UserControl1(); // UserControl1 is a created User control.
this.tbgrid1.Children.Add(obj); // here tbgrid1 is the name of Grid of TabItem.



:)



:)


这篇关于WPF和用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆