Click here to Skip to main content
11,577,258 members (56,935 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF DataTemplate
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.
Posted 1-May-13 4:21am
Pheonyx12K
Edited 1-May-13 6:28am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Pheonyx at 1-May-13 11:06am
   
Having a look at the links, they dont really do what I need. The closest I've seen is the itemselector with itemtemplates, but I don't fully understand them.
Kenneth Haugland at 1-May-13 11:20am
   
I think you need to use the ItemsTemplate to make this work properly as you have specified in you XAML code. However, I could be wrong :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 155
1 OriginalGriff 115
2 Afzaal Ahmad Zeeshan 95
3 Abhinav S 90
4 Lucifier Rocks 85
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 631
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100