xaml窗口列表框 [英] listbox of xaml windows

查看:85
本文介绍了xaml窗口列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为Slide的新Xaml Windows应用程序,其中包含一些元素。我想在listbox元素中看到这个Slides实例的列表。

I created a new Xaml Windows application named Slide with some elements. I want to see list of this Slides instances in listbox element.

List slides = new List();
public void BtnNewSlide_OnClick(object sender, RoutedEventArgs e)
{
    slides.Add(new Slide());
    SlidesList.Items.Clear();
    SlidesList.ItemsSource = slides.ToList();
}



但点击BtnNewSlide时出现此错误:



窗口必须是树的根。不能将Window添加为Visual的子项。

那么如何创建xaml窗口的列表框?


but I get this error when click on BtnNewSlide:

"Window must be the root of the tree. Cannot add Window as a child of Visual."
So how Can I create listbox of xaml windows?

推荐答案

错误只是说你试图将Window控件类型添加到控件的子列表中。

我的意思是,假设创建了一个类型为Window的类xaml(继承你的xaml的类)并再次添加其他新创建的可视化树中的窗口类型。





在您的代码中,我假设Slide类是Window类型并且您正在添加该对象为List,这就是你得到错误的原因。
尝试将Slide类修改为UserControl Type。
Error simply says that you are trying to add Window control type to control's child list.
I mean ,suppose created one xaml of type Window(class from which you are inheriting your xaml) and again adding other class of Window type in newly created visual tree.


In your code, I presume Slide class is of type Window and you are adding that object to List ,That is the reason you are getting error.
Try modifying Slide class as UserControl Type.


这很简单:快速入门:添加ListView和GridView控件(XAML) [ ^ ]


这篇关于xaml窗口列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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