我试图在数据触发器的基础上在2个模板之间切换。但我的应用程序崩溃了,并显示"Object reference not set to a instance of an object“。如果我注释掉模板的setter,它运行得很好。
下面是我的XAML:
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Template" Value="{StaticResource Default}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=FlagVar}" Value="true">
<Setter Property="Template" Value="Error"/>
<Setter Property="Background" Value="{DynamicResource ListErrorBackgroundColor}"/>
<Setter Property="IsSelected" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>编辑-上面的样式在一个ResourceDictionary中,它被合并到消费的XAML中。
发布于 2010-10-29 02:11:28
Value="Error“是什么意思?您不能那样设置模板,请查看本文
http://msdn.microsoft.com/en-us/library/ms788717(VS.85).aspx
https://stackoverflow.com/questions/4045843
复制相似问题