Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi there!
Today I have another question I cannot find a solution for.
I have the following data templates in the Ressources-Section of my window:
XML
<DataTemplate DataType="x:Type crosswordFields:EmptyField">
            <TextBlock MouseDown="FieldSelected" Width="20" Height="20" Tag="{Binding Tag}" Text="-">
            </TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="BuildCrosswordDataTemplate">
            <ListView ItemsSource="{Binding}">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"></StackPanel>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
            </ListView>
        </DataTemplate>


The first would be the template for my data structure i want to show in my ListView, the second one is the template for the ListView itself, which looks like the following:

XML
<ListView Grid.Row="0" Name="lvBuildCrossword" ItemTemplate="{StaticResource BuildCrosswordDataTemplate}"></ListView>

As you can see, this is a ListView which contains further ListView's, but I don't think that that matters.
My problem now is, instead of showing a grid of TextBlocks which show an "-", i get a grid filled with Blocks containing "Crossword.CrosswordFields.EmptyField". Why isn't WPF using the DataTemplate defined for DataType="x:Type crosswordFields:EmptyField" but the default visualization via ToString()?

I hope someone can point me out.
Greets,
Markus
Posted

1 solution

Finally, I found it out myself:
The datatype has be be written
XML
DataType="{x:Type crosswordFields:EmptyField}">

and not
XML
DataType="x:Type crosswordFields:EmptyField">


The missing brackets don't get highlighted, but causing it not to run correct.
But at least I found it out :P
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900