ListView text cell binding

2 posts, 0 answers
  1. Colm
    Colm avatar
    1 posts
    Member since:
    Apr 2017

    Posted 16 Jun Link to this post

    Hi, 

    I am using the text cell and I am wondering if I can bind multiple properties in my class to one cell.

     

    For example, this is what I currently have;

     

    <DataTemplate>

        <telerikListView:ListViewTextCell Text="{Binding client, StringFormat='Client: {0}'}" Detail="{Binding trans_date}" TextColor="Black" DetailColor="LightGray"/>
    </DataTemplate>

     

    And what I want to do is add another part to the stringformat. EG this: "StringFormat='Client{0} ~ ID: {1}"     - Is this possible, and if it is, can someone give me an example. 

    Any assistance is appreciated. Thanks.

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    362 posts

    Posted 19 Jun Link to this post

    Hello Colm,

    You can use a ValueConverter that returns a formatted string that combines multiple property values. 

    For example:

    <telerikListView:ListViewTextCell Text="{Binding Converter={StaticResource ClientItemConverter}}"
            Detail="{Binding trans_date}"
            TextColor="Black"
            DetailColor="Gray"/>

    With that binding, you get the whole object passed to the ValueConverter in the value parameter:

    public class ClientItemConverter  : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var item = value as MyModel;
     
            return $"Client: {item?.client?.name}, ID: {item?.client?.id}";
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    I've attached a demo with the above approach, here is the result at run-time:




    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress 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
Back to Top