为什么我的DataTemplate没有自动应用 [英] Why isn't my DataTemplate applied automatically
问题描述
你好!
今天,我还有一个我找不到解决方案的问题.
我的窗口的资源"部分中包含以下数据模板:
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:
<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>
第一个是我要在ListView中显示的数据结构的模板,第二个是ListView本身的模板,如下所示:
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:
<ListView Grid.Row="0" Name="lvBuildCrossword" ItemTemplate="{StaticResource BuildCrosswordDataTemplate}"></ListView>
如您所见,这是一个包含其他ListView的ListView,但我认为这并不重要.
我现在的问题是,我没有显示一个显示-"的TextBlocks网格,而是用一个包含"Crossword.CrosswordFields.EmptyField"的块填充了一个网格.为什么WPF不使用为DataType ="x:Type crosswordFields:EmptyField"定义的DataTemplate,而是通过ToString()的默认可视化效果?
我希望有人可以指出我.
问候,
Markus
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
推荐答案
最后,我自己发现了它:
数据类型已被写入
Finally, I found it out myself:
The datatype has be be written
DataType="{x:Type crosswordFields:EmptyField}">
而不是
and not
DataType="x:Type crosswordFields:EmptyField">
缺少的括号未突出显示,但导致其无法正确运行.
但是至少我发现了:P
The missing brackets don''t get highlighted, but causing it not to run correct.
But at least I found it out :P
这篇关于为什么我的DataTemplate没有自动应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!