Missing backgroundcolor
This commit is contained in:
@@ -377,7 +377,7 @@ public class SkiaBorder : SkiaLayoutView
|
||||
// Draw background
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
@@ -542,8 +542,8 @@ public class SkiaButton : SkiaView, IButtonController
|
||||
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// BackgroundColor is inherited from SkiaView as SKColor
|
||||
var bgColor = BackgroundColor;
|
||||
// BackgroundColor is inherited from SkiaView as MAUI Color - convert to SKColor for rendering
|
||||
var bgColor = GetEffectiveBackgroundColor();
|
||||
bool hasBackground = bgColor.Alpha > 0;
|
||||
|
||||
// Determine current state color
|
||||
|
||||
@@ -480,11 +480,11 @@ public class SkiaCollectionView : SkiaItemsView
|
||||
{
|
||||
_heightsChangedDuringDraw = false;
|
||||
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -110,11 +110,11 @@ public class SkiaContentPresenter : SkiaView
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// Draw background if set
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -318,7 +318,7 @@ public class SkiaDatePicker : SkiaView
|
||||
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = IsEnabled ? BackgroundColor : new SKColor(245, 245, 245),
|
||||
Color = IsEnabled ? GetEffectiveBackgroundColor() : new SKColor(245, 245, 245),
|
||||
Style = SKPaintStyle.Fill,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SkiaFrame : SkiaBorder
|
||||
HasShadow = true;
|
||||
CornerRadius = 4.0;
|
||||
SetPadding(10.0);
|
||||
BackgroundColor = SKColors.White;
|
||||
BackgroundColor = Colors.White;
|
||||
Stroke = Colors.Transparent;
|
||||
StrokeThickness = 0.0;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ public class SkiaGraphicsView : SkiaView
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// Draw background
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -264,7 +264,7 @@ public class SkiaImageButton : SkiaView
|
||||
}
|
||||
else
|
||||
{
|
||||
bgColor = BackgroundColor;
|
||||
bgColor = GetEffectiveBackgroundColor();
|
||||
}
|
||||
|
||||
// Draw background
|
||||
|
||||
@@ -183,11 +183,11 @@ public class SkiaItemsView : SkiaView
|
||||
Console.WriteLine($"[SkiaItemsView] OnDraw - bounds={bounds}, items={_items.Count}, ItemViewCreator={(ItemViewCreator != null ? "set" : "null")}");
|
||||
|
||||
// Draw background
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -210,9 +210,9 @@ public abstract class SkiaLayoutView : SkiaView
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// Draw background if set (for layouts inside CollectionView items)
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint { Color = BackgroundColor, Style = SKPaintStyle.Fill };
|
||||
using var bgPaint = new SKPaint { Color = GetEffectiveBackgroundColor(), Style = SKPaintStyle.Fill };
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
}
|
||||
|
||||
|
||||
@@ -256,11 +256,11 @@ public class SkiaNavigationPage : SkiaView
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// Draw background
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -138,11 +138,11 @@ public class SkiaPage : SkiaView
|
||||
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
// Draw background color
|
||||
if (BackgroundColor != SKColors.Transparent)
|
||||
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
|
||||
{
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = BackgroundColor,
|
||||
Color = GetEffectiveBackgroundColor(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
@@ -445,7 +445,7 @@ public class SkiaPicker : SkiaView
|
||||
// Draw background
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = IsEnabled ? BackgroundColor : ToSKColor(Color.FromRgb(0xF5, 0xF5, 0xF5)),
|
||||
Color = IsEnabled ? GetEffectiveBackgroundColor() : ToSKColor(Color.FromRgb(0xF5, 0xF5, 0xF5)),
|
||||
Style = SKPaintStyle.Fill,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ public class SkiaSearchBar : SkiaView
|
||||
{
|
||||
Placeholder = "Search...",
|
||||
EntryBackgroundColor = Colors.Transparent,
|
||||
BackgroundColor = SKColors.Transparent,
|
||||
BackgroundColor = Colors.Transparent,
|
||||
BorderColor = Colors.Transparent,
|
||||
FocusedBorderColor = Colors.Transparent,
|
||||
BorderWidth = 0
|
||||
|
||||
@@ -202,7 +202,7 @@ public class SkiaSwipeView : SkiaLayoutView
|
||||
// Draw background
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = item.BackgroundColor,
|
||||
Color = item.GetBackgroundColorSK(),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
canvas.DrawRect(itemBounds, bgPaint);
|
||||
@@ -212,7 +212,7 @@ public class SkiaSwipeView : SkiaLayoutView
|
||||
{
|
||||
using var textPaint = new SKPaint
|
||||
{
|
||||
Color = item.TextColor,
|
||||
Color = item.GetTextColorSK(),
|
||||
TextSize = 14f,
|
||||
IsAntialias = true,
|
||||
TextAlign = SKTextAlign.Center
|
||||
|
||||
@@ -274,7 +274,7 @@ public abstract class SkiaTemplatedView : SkiaView
|
||||
|
||||
if (border.Background is SolidColorBrush bgBrush)
|
||||
{
|
||||
skiaBorder.BackgroundColor = bgBrush.Color.ToSKColor();
|
||||
skiaBorder.BackgroundColor = bgBrush.Color;
|
||||
}
|
||||
|
||||
if (border.Content is Element content)
|
||||
|
||||
@@ -298,7 +298,7 @@ public class SkiaTimePicker : SkiaView
|
||||
|
||||
using var bgPaint = new SKPaint
|
||||
{
|
||||
Color = IsEnabled ? BackgroundColor : new SKColor(245, 245, 245),
|
||||
Color = IsEnabled ? GetEffectiveBackgroundColor() : new SKColor(245, 245, 245),
|
||||
Style = SKPaintStyle.Fill,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
@@ -357,14 +357,15 @@ public abstract class SkiaView : BindableObject, IDisposable, IAccessible
|
||||
|
||||
/// <summary>
|
||||
/// Bindable property for BackgroundColor.
|
||||
/// Uses Microsoft.Maui.Graphics.Color for MAUI compliance.
|
||||
/// </summary>
|
||||
public static readonly BindableProperty BackgroundColorProperty =
|
||||
BindableProperty.Create(
|
||||
nameof(BackgroundColor),
|
||||
typeof(SKColor),
|
||||
typeof(Color),
|
||||
typeof(SkiaView),
|
||||
SKColors.Transparent,
|
||||
propertyChanged: (b, o, n) => ((SkiaView)b).Invalidate());
|
||||
null,
|
||||
propertyChanged: (b, o, n) => ((SkiaView)b).OnBackgroundColorChanged());
|
||||
|
||||
/// <summary>
|
||||
/// Bindable property for WidthRequest.
|
||||
@@ -772,22 +773,30 @@ public abstract class SkiaView : BindableObject, IDisposable, IAccessible
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background color.
|
||||
/// Uses Microsoft.Maui.Graphics.Color for MAUI compliance.
|
||||
/// </summary>
|
||||
private SKColor _backgroundColor = SKColors.Transparent;
|
||||
public SKColor BackgroundColor
|
||||
private SKColor _backgroundColorSK = SKColors.Transparent;
|
||||
public Color? BackgroundColor
|
||||
{
|
||||
get => _backgroundColor;
|
||||
set
|
||||
{
|
||||
if (_backgroundColor != value)
|
||||
{
|
||||
_backgroundColor = value;
|
||||
SetValue(BackgroundColorProperty, value); // Keep BindableProperty in sync for bindings
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
get => (Color?)GetValue(BackgroundColorProperty);
|
||||
set => SetValue(BackgroundColorProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when BackgroundColor changes.
|
||||
/// </summary>
|
||||
private void OnBackgroundColorChanged()
|
||||
{
|
||||
var color = BackgroundColor;
|
||||
_backgroundColorSK = color != null ? color.ToSKColor() : SKColors.Transparent;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the effective background color as SKColor for rendering.
|
||||
/// </summary>
|
||||
protected SKColor GetEffectiveBackgroundColor() => _backgroundColorSK;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the requested width.
|
||||
/// </summary>
|
||||
@@ -1522,9 +1531,9 @@ public abstract class SkiaView : BindableObject, IDisposable, IAccessible
|
||||
}
|
||||
}
|
||||
// Fall back to BackgroundColor
|
||||
else if (BackgroundColor != SKColors.Transparent)
|
||||
else if (_backgroundColorSK != SKColors.Transparent)
|
||||
{
|
||||
using var paint = new SKPaint { Color = BackgroundColor };
|
||||
using var paint = new SKPaint { Color = _backgroundColorSK };
|
||||
canvas.DrawRect(bounds, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ public class SkiaWebView : SkiaView
|
||||
{
|
||||
RequestedWidth = 400.0;
|
||||
RequestedHeight = 300.0;
|
||||
BackgroundColor = SKColors.White;
|
||||
BackgroundColor = Colors.White;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1372,7 +1372,7 @@ public class SkiaWebView : SkiaView
|
||||
if (_isInitialized && _gtkWindow != IntPtr.Zero) return;
|
||||
|
||||
// Draw placeholder when not initialized
|
||||
using var bgPaint = new SKPaint { Color = BackgroundColor, Style = SKPaintStyle.Fill };
|
||||
using var bgPaint = new SKPaint { Color = GetEffectiveBackgroundColor(), Style = SKPaintStyle.Fill };
|
||||
canvas.DrawRect(bounds, bgPaint);
|
||||
|
||||
using var borderPaint = new SKPaint
|
||||
|
||||
@@ -2,19 +2,29 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Microsoft.Maui.Platform;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item in a swipe view. MAUI-compliant using Color types.
|
||||
/// </summary>
|
||||
public class SwipeItem
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public string? IconSource { get; set; }
|
||||
|
||||
public SKColor BackgroundColor { get; set; } = new SKColor(33, 150, 243);
|
||||
/// <summary>
|
||||
/// Background color using MAUI Color type.
|
||||
/// </summary>
|
||||
public Color BackgroundColor { get; set; } = Color.FromRgb(33, 150, 243);
|
||||
|
||||
public SKColor TextColor { get; set; } = SKColors.White;
|
||||
/// <summary>
|
||||
/// Text color using MAUI Color type.
|
||||
/// </summary>
|
||||
public Color TextColor { get; set; } = Colors.White;
|
||||
|
||||
public event EventHandler? Invoked;
|
||||
|
||||
@@ -22,4 +32,22 @@ public class SwipeItem
|
||||
{
|
||||
Invoked?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper to convert BackgroundColor to SKColor for rendering.
|
||||
/// </summary>
|
||||
internal SKColor GetBackgroundColorSK() => new SKColor(
|
||||
(byte)(BackgroundColor.Red * 255),
|
||||
(byte)(BackgroundColor.Green * 255),
|
||||
(byte)(BackgroundColor.Blue * 255),
|
||||
(byte)(BackgroundColor.Alpha * 255));
|
||||
|
||||
/// <summary>
|
||||
/// Helper to convert TextColor to SKColor for rendering.
|
||||
/// </summary>
|
||||
internal SKColor GetTextColorSK() => new SKColor(
|
||||
(byte)(TextColor.Red * 255),
|
||||
(byte)(TextColor.Green * 255),
|
||||
(byte)(TextColor.Blue * 255),
|
||||
(byte)(TextColor.Alpha * 255));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user