when changing property value programmatically, the row background style selector does not apply. You need to scroll the data or resize the control, then the change applies.
The selector works when editing the datagrid value trough the UI, but does not work when changing the value programmatically.
Workaround:
1. Subscribe to the DataGrtid.DataBindingComplete event
2. Use a reflection to get the type - PropertyChanged of the DataChangeFlags internal enumeration.
3. Add a logic if the flag is PropertyChanged, then reapply the style selector.
public partial class MainPage : ContentPage
{
ViewModel vm;
public MainPage()
{
InitializeComponent();
this.vm = new ViewModel();
this.BindingContext = this.vm;
this.datagrid.DataBindingComplete += Datagrid_DataBindingComplete;
}
private void Datagrid_DataBindingComplete(object? sender, DataBindingCompleteEventArgs e)
{
var fType = e.GetType().GetProperty("ChangeFlags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
if (fType != null)
{
var fValue = fType.GetValue(e);
if (fValue != null)
{
Type enumType = fType.PropertyType;
var pChange = Enum.Parse(enumType, "PropertyChanged");
if (fValue.Equals(pChange))
{
this.datagrid.RowBackgroundStyleSelector = new MyRowBackgroundStyleSelector()
{
RowBackgroundStyle = this.Resources["RowBackgroundStyle"] as Style,
AlternateRowBackgroundStyle = this.Resources["AlternateRowBackgroundStyle"] as Style,
RowDetailsBackgroundStyle = this.Resources["RowDetailsBackgroundStyle"] as Style,
AlternateRowDetailsBackgroundStyle = this.Resources["AlternateRowDetailsBackgroundStyle"] as Style,
};
}
}
}
}
}Regards,
Didi
Progress Telerik