This is a migrated thread and some comments may be shown as answers.

RadListBox set item background color based on its value

3 Answers 567 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jegan
Top achievements
Rank 1
Jegan asked on 08 Jan 2015, 03:11 PM
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.

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 09 Jan 2015, 12:51 PM
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.

 
0
Amir
Top achievements
Rank 1
answered on 09 Jun 2015, 02:06 PM


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 :-)

0
Kalin
Telerik team
answered on 11 Jun 2015, 01:03 PM
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
Tags
ListBox
Asked by
Jegan
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Amir
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or