Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
XamaDataGrid, TextColumn, TextColor based whether item is selected.
posted

As in Title. There is SelectedBackground property, which allows you to change the color of background of the row when you selected it. However, XamDataGrid doesnt have same property in case you want to change the TextColor based on Selection.

We kinda tackled it by Implementing converter with Booleen but if List of items is very big, it takes a big hit on performance and it gets really messy. Has anyone tried something else? Or maybe do you have different ideas?

I would appreciate some suggestions! 

Thank you! 

  • 28430
    Verified Answer
    Offline posted

    Hello Wojciech,

    I have been investigating into this behavior that you are looking to achieve, and at the moment, I believe the best recommendation I can make is to use a TemplateColumn with a converter. I am unsure how you are currently using your converter at the moment, but I believe my recommendation shouldn't show a dramatic decrease in performance.

    Using a TemplateColumn, you can define a DataTemplate with a Label element having its Text bound to "{Binding Value}." This will create a reusable DataTemplate, for use with your TemplateColumn.ContentTemplate properties. On your underlying data item, if you have a bool property that designates whether or not your item is selected, you can then bind the TextColor of this Label to "{Binding RowItem.<IsSelectedProperty>}" and use a converter to return your desired "selected row color." From here, you can handle the SelectedItemsChanged event on the XamDataGrid and loop through each of your data items in the event argument's AddedItems and RemovedItems collection, setting the is selected property's value accordingly. This will trigger your converter only for that particular data item, and should allow you to achieve the functionality you are looking for.

    I have attached a sample project to demonstrate the above.

    I believe it is very likely that in a future version we will be implementing a “SelectedTextColor” type of property for the columns in the Xamarin.Forms XamDataGrid as it seems like a bit of an oversight that we didn’t originally. If you would like to express further interest in this feature being developed, I would recommend e-mailing ideas@infragistics.com with this idea. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.

    Please let me know if you have any other questions or concerns on this matter.

    XGrid.zip

    Sincerely,
    Andrew
    Software Developer