使用绑定到一个List<&用户控件GT;我怎么能不显示控制做 [英] Using binding to a List<UserControl> how can I do for not showing the controls

查看:120
本文介绍了使用绑定到一个List<&用户控件GT;我怎么能不显示控制做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我工作的代码:

<TextBlock TextWrapping="Wrap" Text="{Binding Objective}" Grid.Column="0" VerticalAlignment="Center" FontWeight="Bold" />
<ItemsControl ItemsSource="{Binding Problems}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Rectangle Stroke="Black" Height="20" Width="20" Margin="1,0" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>

当设置的ItemsSource为列表框。它包含:

When set ItemsSource to listBox. It contains:

List<Container>
(Below container properties)
    - Objective: string
    - Problems: List<UserControls>



看这句话:<的ItemsControl的ItemsSource ={绑定问题} >
在代码中,存在的问题是用户控件的列表。当我打开程序时,列表框显示的控件在用户控制和它应该显示矩形。

Look at this line: <ItemsControl ItemsSource="{Binding Problems}" > In the code, Problems is a list of UserControls. When I load the program, the listbox is showing the controls from the user control and it's supposed to show the rectangle.

我在做什么错了?

推荐答案

看Visual Studio中的输出窗口,你会看到这一点:

Look at the Output-window of Visual Studio and you will see this:

System.Windows.Data错误:26:ItemTemplate中和ItemTemplateSelector的项目已经ItemsControl的的容器类型的被忽略; TYPE =XXX

System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type; Type='XXX'

它不适用于作为项目可直接添加的模板。

It does not apply the template as the Items can be added directly.

我的意思大约包裹你的控件是您创建其中包含的用户控件的属性一类,例如:

What i meant about wrapping your controls is that you create a class which holds a property for the UserControl, e.g.:

 Problems : List<ProblemContainer>





public class ProblemContainer
{
    public UserControl Problem { get; set; }
}

这篇关于使用绑定到一个List&LT;&用户控件GT;我怎么能不显示控制做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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