twreid
twreid

Reputation: 1453

Change ItemsControl ItemsTemplate based on data value

I have an ItemsControl bound to a Dictionary and am trying to apply a template based on the value of the Dictionaries key. I am trying to do:

<ItemsControl ItemsSource="{Binding Path=CommonItems, Mode=OneWay}">
    <ItemsControl.Style>
        <Style TargetType="ItemsControl">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Key}" Value="authentication">
                    <Setter Property="ItemTemplate" Value="{StaticResource AuthenticationTemplate}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ItemsControl.Style>
</ItemsControl>

That doesn't work at all and my errors say Key doesn't exist on ItemsControl. That leads me to believe that It is using my TargetType to search for the binding. So how do I do this and have it actually use the ItemsSource?

Upvotes: 0

Views: 227

Answers (1)

brunnerh
brunnerh

Reputation: 184296

If you want to do this per-item, i would suggest using an ItemTemplateSelector.

Upvotes: 1

Related Questions