views:

138

answers:

1

Why does the DataTemplate line break the WPF designer in Visual Studio 2008?

The program compiles and runs properly. The DataTemplate is applied as it should. However the entire DataTemplate block of code is underlined in red, and when I simply "build" the program without running, I get the error "Type reference cannot find public type named 'Character'"

How come it can't find it in the designer yet the program applies the template properly?

<UserControl x:Class="WPF_Tests.Tests.TwoCollecViews.TwoViews"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:DetailsPane="clr-namespace:WPF_Tests.Tests.DetailsPane" 
    >
   <UserControl.Resources>

      <DataTemplate DataType="{x:Type DetailsPane:Character}">
         <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=Name}"></TextBlock>
         </StackPanel>
      </DataTemplate>

   </UserControl.Resources>

   <Grid>
      <ListBox ItemsSource="{Binding Path=Characters}"  />
   </Grid>
</UserControl>

EDIT: I am being told that this may be a bug in Visual Studio 2008, as it worked correctly in 2010. You can download the code here: http://www.mediafire.com/?z1myytvwm4n - The Test/TwoCollec xaml file's designer will break with this code.

+2  A: 

Yes, it's a bug in Visual Studio 2008. You can workaround it by changing your assembly name (right-click on Project "WPF Tests"/Properties) from "WPF Tests" to "WPF_Tests". I tried it with your project and it seems to work (after restarting Visual Studio).

(Credit for this workaround goes to: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21d72064-354c-432e-8227-ba4e21f4089f)

Heinzi