CellStyleSelector with parameter

2 posts, 0 answers
  1. Dario Concilio
    Dario Concilio avatar
    180 posts
    Member since:
    Apr 2016

    Posted 14 Apr 2016 Link to this post

    Hi to all,

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






    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
    03.    public override Style SelectStyle(object item, DependencyObject container)
    04.    {
    05.        if (item is MyItem)
    06.        {
    07.            MyItem currentItem = item as MyItem;
    09.            //Can I receive a specific property on to test?
    10.            //Can I receive a parameter (like Command) ?
    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; }

  2. Ivan Ivanov
    Ivan Ivanov avatar
    1218 posts

    Posted 19 Apr 2016 Link to this post


    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.

    Ivan Ivanov
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top