I'm trying to override the default ListviewItem
in ListView
with my custom own, so i used GetContainerForItemOverride()
. It worked as expected, but when i try to override the default template
it throw the following exception:
InvalidOperationException: ''Template' property cannot be set in the current element's Template'
Am i missing anything here?
<Style TargetType="{x:Type local:StockViewItem}">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="MinHeight" Value="60px" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:StockViewItem}">
<Grid Background="Transparent">
<Border
x:Name="ContentHost"
Margin="0"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding DefaultBackground}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid>
<GridViewRowPresenter x:Name="gridrowPresenter" Content="{TemplateBinding Property=ContentControl.Content}" />
<ContentPresenter
x:Name="contentPresenter"
Content="{TemplateBinding Property=ContentControl.Content}"
Visibility="Collapsed" />
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="GridView.ColumnCollection" Value="{x:Null}">
<Setter TargetName="contentPresenter" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="ContentHost" Property="Background" Value="{Binding RelativeSource={RelativeSource AncestorType=local:StockViewItem}, Path=ActiveBackground, Mode=TwoWay}" />
<Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Cursor" Value="Hand" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentHost" Property="Background" Value="{Binding RelativeSource={RelativeSource AncestorType=local:StockViewItem}, Path=HoverBackground, Mode=TwoWay}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
As noted by Clemens, i had the Template
setter in a trigger inside the Template
itself instead of the Style
triggers.