Hello.
Sorry for my "English" :)
VirtualGrid was added in xaml markup and it was subscribed to OverlayBrushesNeeded using EventToCommandBehavior.
<
telerik:RadVirtualGrid
Name
=
"VirtualGrid"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
telerik:StyleManager.Theme
=
"Office2016"
CanUserInsertRows
=
"False"
CanUserEdit
=
"True"
InitialRowCount
=
"10"
InitialColumnCount
=
"10"
MeasureTextOnRender
=
"True"
DataProvider
=
"{Binding DataProvider}"
LinesVisibility
=
"Both"
CanUserSortColumns
=
"False"
CanUserFilterColumns
=
"False"
RowHeaderWidth
=
"0"
ColumnWidth
=
"150"
Grid.Column
=
"2"
>
<
telerik:RadVirtualGrid.ContextMenu
>
<
ContextMenu
ItemsSource
=
"{Binding ContextMenuModel.Items}"
></
ContextMenu
>
</
telerik:RadVirtualGrid.ContextMenu
>
<
telerik:EventToCommandBehavior.EventBindings
>
<
telerik:EventBinding
PassEventArgsToCommand
=
"True"
Command
=
"{Binding VirtualGridOverlayBrushesNeeded}"
EventName
=
"OverlayBrushesNeeded"
/>
<
telerik:EventBinding
PassEventArgsToCommand
=
"True"
Command
=
"{Binding VirtualGridCellDecorationsNeeded}"
EventName
=
"CellDecorationsNeeded"
/>
</
telerik:EventToCommandBehavior.EventBindings
>
</
telerik:RadVirtualGrid
>
There are 2 commands in my ViewModel.
public
ICommand VirtualGridCellDecorationsNeeded
{
get
=> _virtualGridCellDecorationsNeeded;
}
public
ICommand VirtualGridOverlayBrushesNeeded
{
get
=> _virtualGridOverlayBrushesNeeded;
}
_virtualGridCellDecorationsNeeded =
new
Telerik.Windows.Controls.DelegateCommand(OnCellDecorationsNeeded);
_virtualGridOverlayBrushesNeeded =
new
Telerik.Windows.Controls.DelegateCommand(OnOverlayBrushesNeeded);
public
void
OnCellDecorationsNeeded(
object
sender)
{
if
(sender
is
CellDecorationEventArgs args)
{
if
(args.ColumnIndex % 2 == 0)
{
args.Background = Brushes.Red;
args.Foreground = Brushes.Black;
args.CellTextAlignment = TextAlignment.Left;
}
else
{
args.Background = Brushes.Yellow;
args.Foreground = Brushes.Red;
args.CellTextAlignment = TextAlignment.Left;
}
}
}
public
void
OnOverlayBrushesNeeded(
object
sender)
{
if
(sender
is
OverlayBrushesEventArgs args)
{
args.Brushes.Add(Brushes.Red);
args.Brushes.Add(Brushes.Yellow);
}
}
CellDecorationsNeeded is triggered, but OverlayBrushesNeeded is not, which makes it impossible to set colors for cells. Please tell me what I'm doing wrong.