如何在WPF中将多个内容与DataTemplate动态绑定? [英] How to bind multiple contents with the DataTemplate dynamically in WPF?
问题描述
I want to create a TabItem with one ListBox and one WebBrowser type contents
在其中, 我要动态创建的字体.我可以正确添加标题部分,
但我不知道如何在DataTemplate中添加多个内容.
推荐答案
您应该将TabItem的Content属性设置为单个面板.然后,您可以将ListBox和WebBrowser都添加到此面板中,例如:
You should set the Content property of the TabItem to a single Panel. You can then add both the ListBox and the WebBrowser to this Panel, e.g.:
private TabItem AddTabItem()
{
TabItem tab = new TabItem();
WebBrowser wbr = new WebBrowser();
wbr.MaxHeight = 1550;
wbr.MaxWidth = 1550;
wbr.Navigate("https://microsoft.com");
DockPanel.SetDock(wbr, Dock.Bottom);
ListBox listBox = new ListBox();
DockPanel dockPanel = new DockPanel();
dockPanel.Children.Add(wbr);
dockPanel.Children.Add(listBox);
tab.Content = dockPanel;
return tab;
}
Please refer to the answer at stackoverflow for more information: http://stackoverflow.com/questions/41096540/how-to-bind-multiple-contents-with-the-datatemplate-dynamically-in-wpf
还请记住通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.
Please also remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于如何在WPF中将多个内容与DataTemplate动态绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!