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

CellStyleSelector with parameter

1 Answer 221 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dario Concilio
Top achievements
Rank 2
Dario Concilio asked on 14 Apr 2016, 12:55 PM

Hi to all,

I would to change a CellStyle based to more specific properties of Currenti Item.

Example:

ItemA.Property1

ItemA.Property2

ItemA.Property3

ItemB.Property1
ItemB.Property2
ItemB.Property3

ItemA and ItemB derives from ItemBase that it has CanProperty1, CanProperty2 and CanProperty3 (all 3 boolean)

Now, I would change style to show cell content's only if CanPropertyX = true, if no it will shows other cellstyle (empty cell)

Actually I'm using StyleSelector pattern, but it receives all currenti item, it doesn't know witch property it refer.

How can I do this?

 

01.public class MyItemStyle : StyleSelector
02.{
03.    public override Style SelectStyle(object item, DependencyObject container)
04.    {
05.        if (item is MyItem)
06.        {
07.            MyItem currentItem = item as MyItem;
08.             
09.            //Can I receive a specific property on to test?
10.            //Can I receive a parameter (like Command) ?
11.             
12.            if (currentItem.MyProperty1)
13.                return MyFirstItemStyle;
14.            else
15.                return MySecondItemStyle;
16.        }
17.        return null;
18.    }
19.    public Style MyFirstItemStyle { get; set; }
20.    public Style MySecondItemStyle { get; set; }
21.}

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 19 Apr 2016, 12:58 PM
Hello,

If I understand your requirements correctly, the StyleSelector should refer to a different property for each of the items, am I right? Is this logic defined in the ViewModel, or in some other utility class, so that a reference to it can be passed to the StyleSelector. The logic that invokes SelectStyle is internal and it cannot be modified through the public API. Would it be possible for you to shed some more light on the specific goal that you are trying to achieve, so that we can think of an appropriate solution.

Regards,
Ivan Ivanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Dario Concilio
Top achievements
Rank 2
Answers by
Ivan Ivanov
Telerik team
Share this question
or