RadListBox set item background color based on its value

4 posts, 0 answers
  1. Jegan
    Jegan avatar
    9 posts
    Member since:
    Jan 2015

    Posted 08 Jan 2015 Link to this post

    I have a RadListBox as a messagebox which is bound to a list of messages from the system. When there is a fault in the system a fault message is recorded, I want to highlight this message with red background. Is there any way to change the background of an item based on its value.

    I tried this code but it didn't have access to background property.
    this.ListBox.Items.CurrentChanged += (sender, args) =>
    {
        for (int i = 0; i < this.ListBox.Items.Count; ++i)
        {
            var item = this.ListBox.Items[i];
     
            if (item.ToString().StartsWith("Fault"))
            {
                ListBox.Items[i]............????????? Looking for background property.
            }
        }
    };


    Thanks.
  2. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 09 Jan 2015 Link to this post

    Hi Jegan,

    In order to achieve the desired appearance of RadListBox the default RadListBoxItemStyle needs to be modified. Binding the Background property of the "SelectedVisual" border to a converter that based on the SelectedItem property sets different background for the items the desired should be accomplished.

    We have created a sample project that demonstrates the described approach - please, check it. Also, please, notice that we used Implicit Styles.

    We hope this will help you.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Amir
    Amir avatar
    3 posts
    Member since:
    Jul 2012

    Posted 09 Jun 2015 in reply to Nasko Link to this post



    You must be kidding!

    Seriously!

    For item selection color change there must be that much code
    change in App.XAML and several other files! How do you expect people figure
    this out.

    And you call your libraries the most intuitive RAD! Selling
    it for thousands dollars!

    What are you smoking out there in Telerik development :-)

  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 11 Jun 2015 Link to this post

    Hi Amir,

    I have already replied in the other forum thread, I'm also pasting my reply in this thread:

    Thank you for your feedback. Indeed in this particular case to achieve such a custom appearance of the control you would have to exact and modify the default template of the RadListoBoxItem. As for fact that in the sample project we have modified couple of xaml files - this is so because we are using the Implicit Styling approach. The same result can be achieved with changes in a single file. Note that using Implicit Styles provides the following benefits:

    - Custom themes are done much easier - created only via merged dictionaries
    - Basing styles on a theme is simple
    - Assemblies have smaller size
    - Improved Blend support


    If you have you any other questions, do not hesitate to contact us.

    Regards,
    Kalin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top