列表视图模板不适用 [英] Listview templates not applying
问题描述
大家好,
所以我正在研究一个在两个系统之间验证和导入一些数据的例程。
两个例程都将结果输出到对象列表中,我试图在我的GUI中绑定到这个列表。
我想要实现的目标是每种类型的结果,无论是验证结果还是导入结果都有自己的数据模板。
例如:
验证结果应如下所示:
编号:结果
导入结果应如下所示:
来源编号:已导入否:已打印
问题是我的数据模板似乎没有被选中,我不知道为什么。
< ListView ItemsSource = {Binding Path = Results} >
< ListView.Resources >
< DataTemplate DataType = { x:输入customTypes:ValidationResult} >
< StackPanel 方向 = Horizonta l >
< TextBlock 文字 = {Binding Path = InvoiceNumber} / >
< TextBlock 文字 = {Binding Path = ResultString} / >
< / StackPanel >
< / DataTemplate >
< / ListView.Resources >
< / ListView >
我肯定我错过了一些明显的东西,但我不确定是什么。
此时此刻我有只设计了ValidationResult的数据模板,但这是因为目前只有验证将其结果添加到Results集合中。
- ----------------------------------------
细化
只是在这里添加一些额外的信息。
我可能有一个如下所示的结果列表:
ValidationResult
ValidationResult
ImportResult
ImportResul t
我的列表视图绑定到类型的属性ReadOnlyCollection< object>
包含结果列表。
我上面显示的数据模板是我想在显示项目时使用的两个不同模板之一。但是,此时,即使该单个模板也不显示数据。我有一个listview,显然有项目,因为屏幕上显示可选项目,但他们不使用模板,我不知道为什么。
< blockquote>我通常将DataTemplate放在GridView控件中:
http://huydinhpham.blogspot.no/2008/11/using-listvew-to-display-complex-data.html [ ^ ]
或者您可以使用ItemsTemplate这样做:
http://stackoverflow.com/questions/483542/listbox-with-itemtemplate-and-scrollbar [ ^ ]
Hi guys,
So I am working on a routine that validates and imports some data between two systems.
both routines output their results into a list of objects and I am trying to bind to this list in my GUI.
What I would like to achieve is that each type of result, be it a validation result or an import result to have its own data template.
For example:
Validation result should look like this:
Number : Result
And import result should look like this:
Source No: Imported No: Printed
The issue I have is that my data template does not appear to be selected and I''m not sure why.
<ListView ItemsSource="{Binding Path=Results}">
<ListView.Resources>
<DataTemplate DataType="{x:Type customTypes:ValidationResult}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=InvoiceNumber}" />
<TextBlock Text="{Binding Path=ResultString}" />
</StackPanel>
</DataTemplate>
</ListView.Resources>
</ListView>
I''m sure I am missing something obvious, but I''m not sure what.
At this time I have only devised the data template for the ValidationResult, but this is because only validation is currently adding its results to the Results collection.
-----------------------------------------
Refinement
Just to add some additional information here.
I might have a results list that looks like this:
ValidationResult
ValidationResult
ImportResult
ImportResult
My list view is bound to a property of type ReadOnlyCollection<object>
which contains the result list.
My data template shown above is one of two different templates I want to use when displaying the items. However, at this time, even that single template is not displaying data. I have a listview, that clearly has items in as there are selectable items shown on screen, however they do not use the templates and I''m not sure why.
I usuall put the DataTemplate in a GridView control:
http://huydinhpham.blogspot.no/2008/11/using-listvew-to-display-complex-data.html[^]
or you could do it with the ItemsTemplate like this:
http://stackoverflow.com/questions/483542/listbox-with-itemtemplate-and-scrollbar[^]
这篇关于列表视图模板不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!