如何在WPF中将多个内容与DataTemplate动态绑定? [英] How to bind multiple contents with the DataTemplate dynamically in WPF?

查看:225
本文介绍了如何在WPF中将多个内容与DataTemplate动态绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
    }

有关更多信息,请参考stackoverflow上的答案:

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屋!

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