BUG: 'Converter' doesn't work for nested ItemsControl

I think there is a bug concerning 'Converters' when using nested bindings. The example program in this solution should print the following output:

1:1.1
2:2.1
2.2
3:3.1
3.2
3.3

The example program iterates through two levels. I only use a converter for the second level. The converter doesn't convert anything, but is used to illustrate the problem. The output that I receive looks like:

1:1.1
2:
3:

I think this is a bug in WPF. Compile and run the example program and you'll see what is wrong. Remove the 'Converter={...}' part from the 'TextBlock' and you'll see that everything works fine. Checkhttp://home.ict.nl/~ramklein/Download/ExposeBug.zip for the complete example that clearly illustrates the bug. Does anyone have details (or a workaround) for this problem?

[2045 byte] By [RamondeKlein] at [2007-12-30]
# 1
Hi there

Interesting find.

This potentially looks similar to a bug I discovered when only the first item in an ItemsControl was being rendered properly - see this forum post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1231448&SiteID=1

Well I have a workaround - that is to move your nested DataTemplate to the Window.Resources section like this:

<DataTemplate x:Key="MyTemplate">
<!-- BUG: Enable following line to display bug with Converter -->
<TextBlock Text="{Binding XPath=@name, Converter={StaticResource nullConverter}, Mode=TwoWay}"/>
<!-- BUG: Enable following line to show how it should have looked like -->
<!--<TextBlock Text="{Binding XPath=@name}"/>-->
</DataTemplate>

Then refer to it in your items control

<!-- BEGIN: Iterate through all the level 2 items-->
<ItemsControl ItemsSource="{Binding XPath=*}" ItemTemplate="{StaticResource MyTemplate}">
</ItemsControl>
<!-- END: Iterate through all the level 2 items-->

neilmosafi at 2007-10-9 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
Thanks for your reply. Moving the 'DataTemplate' to the resource is the solution for this problem. Did you report the bug to Microsoft?
RamondeKlein at 2007-10-9 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
Hmm no actually, I assumed the monitor these forums as they run them!

I guess I should though do you have a pointer to a URL for reporting WPF bugs? Unless you do it... either way let me know

Regards
Neil

neilmosafi at 2007-10-9 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified