CellStyleSelector with parameter

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

    Posted 14 Apr Link to this post

    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.}

  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 19 Apr Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top