Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:50:21+00:00 2026-06-12T17:50:21+00:00

I remember, some time ago, seeing an example on MSDN of how you could

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:50:22+00:00Added an answer on June 12, 2026 at 5:50 pm

    You need to create a StyleSelector and assign it to the ItemContainerStyleSelector property. In the selector, just pick a style based on the type of the item.

    class MyStyleSelector : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            if (item is FileItem)
                return Application.Current.Resources["FileItemStyle"];
            if (item is DirectoryItem)
                return Application.Current.Resources["DirectoryItemStyle"];
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can remember that some time ago when I created a UserControl in Visual
I remember coming across an article on I think CodeProject quite some time ago
I did a REGEX pattern some time ago and I don't remember its meaning.
I remember reading some time ago that there were cpu cards for systems to
I remember some rules from a time ago (pre-32bit Intel processors), when was quite
A long time ago I remember I could do this in Turbo Pascal 7.
I remember from some time ago reading about a commandline tool that explains C
I remember few weeks ago when I reorgnized our code and created some namespaces
I found some time ago a CSS framework like Clever CSS but I don't
A long time ago I used to program in C for school. I remember

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.