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

Multiple StyleSelectors

5 Answers 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
azbola
Top achievements
Rank 1
azbola asked on 24 Feb 2011, 11:06 AM
Hi all,

I have a requirement where I need to assign 2 style selectors to a cell and have them evaluate in a certain order.
Is this possible?

I have two styles, let us assume that they do the following (not the real cases but demonstrate the point):

1) Turns a background red if the value is over a certain number - let us assume this is called TooBigStyleSelector
2) Turns a background blue if the value has recently been updated - let us assume this is called RecentUpdateStyleSelector

Now I can apply either of these selectors to a gridviewcell independently, but for one cell I would like to apply both.
The rule should be that TooBigStyleSelector has a higher priority the RecentUpdateStyleSelector so that if the cell gets updated it goes blue, but it the value that it is updated to is too big it goes red.

How can I acheive this? I suspect I can do it by calling one style selector from the other, but would prefer to do it in Xaml if possible.

Many thanks,
Dave A.

5 Answers, 1 is accepted

Sort by
0
azbola
Top achievements
Rank 1
answered on 24 Feb 2011, 11:28 AM
OK, so I tried calling another StyleSelector from the first StyleSelector and returning the style that was returned by it but this doesn't work because the style returned by the second selector is not defined as a property in the resource for the first StyleSelector so it doesn't know what actual style to use.
0
Pavel Pavlov
Telerik team
answered on 25 Feb 2011, 10:39 AM
Hello azbola,

Since there is no support for more than one style selector we need to find some alternative.
Here is what I can think of at a first glance ( 2 approaches ) :

1. Before having style selectors , we used to bind the background color to a certain property trough an IValueConverter converter.
So you can try this in your scenario - use a style selector for the one condition and binding for the second.

or
2. Try to combine the logic in a single style selector . Is there something preventing you to combine the logic for both condition in the SelectStyle method of a single style selector ?


* As a side note - I can be more specific and even try  give some sample implementation if you give me some more details - e.g. how do you track which item has been modified ? Is this a property on the business object or something else ?

Greetings,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
azbola
Top achievements
Rank 1
answered on 25 Feb 2011, 10:46 AM
Hi Pavel,

Thank you for your reply.

I have actually already gone down the second route you suggested and combined the logic into a single style selector.
The reason I did not want to do this is that although it works, it does not seem to me to be the neatest design as I now have to apply this very generic style selector to all the cells, even though most of those cells will only use part of the logic inside it.

So now, instead of having two (or more) style selectors such as:
TooBigStyleSelector
RecentUpdateStyleSelector
AnotherStyleSelector
YetAnotherStyleSelector

I have something like:
AllLogicStyleSelector

and have to apply this to all the cells that need any of the logic from the individual selectors.

Anyway, like I said this does work but I think having the ability to chain style selectors would be a very useful feature - can I add this as a feature request somewhere?

Many thanks,
Azbola (Dave Asbury)
0
Pavel Pavlov
Telerik team
answered on 25 Feb 2011, 04:41 PM
Hi azbola,

First of all - nice to hear the issue was solved.
About your second query - I have added this as a feature request . You can find it here :

http://www.telerik.com/support/pits.aspx#/public/silverlight/4945


All the best,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
azbola
Top achievements
Rank 1
answered on 25 Feb 2011, 04:49 PM
Many thanks!
Tags
General Discussions
Asked by
azbola
Top achievements
Rank 1
Answers by
azbola
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or