问题描述
app.xaml中有一个DataTemplate,它将视图绑定到视图模型.
I have a DataTemplate in app.xaml that binds a view to a viewmodel.
<Application.Resources>
<DataTemplate DataType="{x:Type vm:someviewmodeltype}">
<vw:somevwcontrol />
</DataTemplate>
</Application.Resources>
如果没有样式,则不会应用上述模板.我放上样式的那一刻,就像...
the above template doesn't get applied if there are no styles. The moment I put a style, something like ...
<Application.Resources>
<DataTemplate DataType="{x:Type vm:someviewmodeltype}">
<vw:somevwcontrol />
</DataTemplate>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="20"></Setter>
</Style>
</Application.Resources>
数据模板被拾取并产生期望的结果...我不确定在那里发生了什么...有人可以澄清吗?
datatemplate gets picked up and produces the desired results ... I am not sure whats happening there ... could anybody clarify this ?
谢谢.
推荐答案
回答了类似的问题.问题并不完全相同,一个包含合并字典的被跳过,但是很可能是相同的错误.
Answered a similar question here. The question is not exactly the same, that one contained merged dictionaries being skipped but it's most likely the same bug.
这是一个优化错误,请参见此链接.
This is an optimization bug, see this link.
我看到您也已经找到了解决方法,只需在App.xaml中添加默认的虚拟样式即可.它不需要任何setter等,类似的事情也可以
I see you've already found the workaround as well, just add a default dummy style in App.xaml. It doesn't have to have any setters etc, something like this will do as well
<Application.Resources>
<DataTemplate DataType="{x:Type vm:someviewmodeltype}">
<vw:somevwcontrol />
</DataTemplate>
<Style TargetType="{x:Type Rectangle}" />
</Application.Resources>
这篇关于没有任何样式的app.xaml中的datatemplate是否不会被拾取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!