I remember, some time ago, seeing an example on MSDN of how you could change the Style of a LitViewItem based on the class type of the object in that item.
Can anyone point me in the direction of this example or one like it? I’m converting a file manager and I’d love to use this approach.
Thanks,
Tom P.
EDIT:
OK, I don’t think I described my problem correctly. Let me try code:
public class IOItem
{
}
public class FileItem : IOItem
{
}
public class DirectoryItem : IOItem
{
}
public class NetworkItem : IOItem
{
}
Now, given the above classes can I create a Style that changes based on the class type of the final object? For example:
<Style TargetType="{x:Type FileItem}">
<Setter Property="Background" Value="Red" />
</Style>
<Style TargetType="{x:Type DirectoryItem}">
<Setter Property="Background" Value="Green" />
</Style>
Is this possible?
You need to create a
StyleSelectorand assign it to theItemContainerStyleSelectorproperty. In the selector, just pick a style based on the type of the item.