views:

13

answers:

1

I'm trying to switch between 2 templates on the basis of a data trigger. But I app crashes with the "Object reference not set to an instance of an object." If I comment out the setter for the template it runs fine.

Here's my 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>

EDIT- The above styling is in a ResourceDictionary which is merged into the consuming XAML.

+1  A: 

What is the Value="Error" means? you can't set the Template like that, check this article

http://msdn.microsoft.com/en-us/library/ms788717(VS.85).aspx

A_Nablsi
Can't believe the answer was as silly as missing a {StaticResource} qualifier! Thanks!
Krishter
Good luck!!! :)
A_Nablsi