Bind MyRatingCellEditor background color to the cell's background

This commit is contained in:
Michael Bucari-Tovo 2023-01-09 14:06:06 -07:00
parent eee785377f
commit 4e80af5c53

View File

@ -2,6 +2,9 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using DataLayer; using DataLayer;
using LibationAvalonia.ViewModels;
using ReactiveUI;
using System;
namespace LibationAvalonia.Controls namespace LibationAvalonia.Controls
{ {
@ -29,6 +32,21 @@ namespace LibationAvalonia.Controls
myRatingElement.Bind(BindingTarget, Binding); myRatingElement.Bind(BindingTarget, Binding);
} }
void setControlBackground(object dataContext)
{
if (dataContext is GridEntry ge)
myRatingElement.Background = ge.BackgroundBrush;
}
setControlBackground(cell?.DataContext);
var subscriber =
cell
?.ObservableForProperty(g => g.DataContext)
?.Subscribe(ctx => setControlBackground(ctx?.Value));
myRatingElement.DetachedFromVisualTree += (_, _) => subscriber?.Dispose();
return myRatingElement; return myRatingElement;
} }