如何添加页面WPF TabControl的到? [英] How to add WPF page to tabcontrol?
本文介绍了如何添加页面WPF TabControl的到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的主WPF窗口
I have this main wpf window
和这个WPF页
我要加入这个页面主窗口中的TabControl
I need to add this page to tabcontrol in main window
这是我的OnRender方法
This is my OnRender method
protected override void OnRender(DrawingContext drawingContext)
{
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
pan1.Items.Add(tabitem);
Page1 page1 = new Page1();
tabitem.Content = new Page1();
ISFirstRender = false;
}
base.OnRender(drawingContext);
}
我面对此异常的同时选择新标签$ B $应用程序运行后, b
after the application running I faced this exception while selecting the new tab
我需要知道如何添加WPF页面现有tabcontroll
I need to know how to add wpf page to existing tabcontroll
推荐答案
如果你想添加一个新的页
,而不是一个用户控件
,您可以创建一个新的帧
对象,并将页面在那里。
If you want to add a new Page
, as opposed to a UserControl
, you can create a new Frame
object and place the page in there.
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
Frame tabFrame = new Frame();
Page1 page1 = new Page1();
tabFrame.Content = page1;
tabitem.Content = tabFrame;
pan1.Items.Add(tabitem);
ISFirstRender = false;
}
这篇关于如何添加页面WPF TabControl的到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文