public class RowStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
var record = (item as DataRow).RowData as Model;
if (record == null)
return base.SelectStyle(item, container);
if (record.IsIgnored)
{
return App.Current.Resources["IgnoredStyle"] as Style;
}
else if(record.IsInDelivery)
{
return App.Current.Resources["DeliveredStyle"] as Style;
}
return base.SelectStyle(item, container);
}
}
public class SfDataGridBehavior : Behavior<SfDataGrid>
{
protected override void OnAttached()
{
base.OnAttached();
this.AssociatedObject.CurrentCellValueChanged += AssociatedObject_CurrentCellValueChanged;
this.AssociatedObject.CurrentCellEndEdit += AssociatedObject_CurrentCellEndEdit;
}
bool isValueChanged = false;
private void AssociatedObject_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
{
if (!isValueChanged)
return;
var grid = sender as SfDataGrid;
//getting GridCell
var cell =
(grid.SelectionController.CurrentCellManager.CurrentCell.Renderer as GridCellRendererBase)
.CurrentCellElement;
if (cell != null)
{
grid.UpdateDataRow(e.RowColumnIndex.RowIndex);
}
isValueChanged = false;
}
private void AssociatedObject_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs e)
{
isValueChanged = true;
}
} |
<Application.Resources>
<Style TargetType="syncfusion:VirtualizingCellsControl" x:Key="IgnoredStyle">
<Setter Property="Background" Value="DarkGray"/>
</Style>
<Style TargetType="syncfusion:VirtualizingCellsControl" x:Key="DeliveredStyle">
<Setter Property="Background" Value="LightGreen"/>
</Style>
</Application.Resources>
<local:RowStyleSelector x:Key="rowStyleSelector"/>
<syncfusion:SfDataGrid x:Name="sfdatagrid" AutoGenerateColumns="False"
AllowEditing="True"
RowStyleSelector="{StaticResource rowStyleSelector}"
ItemsSource="{Binding OrderInfoCollection}" >
|
<Window.Resources>
<Style TargetType="syncfusion:VirtualizingCellsControl">
<Style.Triggers>
<DataTrigger Binding="{Binding IsIgnored,
UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Background" Value="DarkGray"/>
</DataTrigger >
<DataTrigger Binding="{Binding IsInDelivery,
UpdateSourceTrigger=PropertyChanged}" Value="True" >
<Setter Property="Background" Value="LightGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources> |
HI
I tried the first sample, but using current VS 2019 with net 4.72 I am getting a lot of errors, and cant get the sample running.