a color picker control for .NET MAUI powered by SkiaSharp.
this is largely based on XFColorPickerControl
for Xamarin.Forms (https://github.com/UdaraAlwis/XFColorPickerControl) by UdaraAlwis who allowed me to publish this updated version of the control 🙌
initialize SkiaSharp in your app by calling the UseSkiaSharp
method on the MauiAppBuilder
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseSkiaSharp()
...
add namespace
xmlns:controls="clr-namespace:Maui.ColorPicker;assembly=Maui.ColorPicker"
create control
<controls:ColorPicker
x:Name="ColorPicker"
ColorFlowDirection="Horizontal"
ColorSpectrumStyle="ShadeToHueStyle"
PickedColorChanged="ColorPicker_PickedColorChanged"
PointerRingBorderUnits="0.3"
PointerRingDiameterUnits="0.7">
</controls:ColorPicker>
ColorPicked
:Gets or sets the Picked Color of the Color Picker.
XAML:
<controls:ColorPicker
x:Name="ColorPicker"
ColorPicked={Binding UserPickedColor}
... >
</controls:ColorPicker>
C#:
var colorPicked = ColorPicker.ColorPicked;
BaseColorList
:Change the available base Colors on the Color Spectrum, of the Color Picker. This will take a List of strings included with Color names or hex values which is held in an IEnumerable.
<controls:ColorPicker
x:Name="ColorPicker"
... >
<controls:ColorPicker.BaseColorList>
<x:Array Type="{x:Type x:String}">
<!-- Yellow -->
<x:String>#ffff00</x:String>
<!-- Aqua -->
<x:String>#00ffff</x:String>
<!-- Fuchsia -->
<x:String>#ff00ff</x:String>
<!-- Yellow -->
<x:String>#ffff00</x:String>
</x:Array>
</controls:ColorPicker.BaseColorList>
</controls:ColorPicker>
ColorPicker.BaseColorList = new List<string>()
{
"#00bfff",
"#0040ff",
"#8000ff",
"#ff00ff",
"#ff0000",
};
ColorFlowDirection
:Change the direction in which the Colors are flowing through on the Color Spectrum, of the Color Picker. This will allow you to set whether the Colors are flowing through from left to right, Horizontally or top to bottom, Vertically
<controls:ColorPicker
x:Name="ColorPicker"
ColorFlowDirection="Horizontal"
... >
</controls:ColorPicker>
ColorPicker.ColorFlowDirection =
Udara.Plugin.controls.ColorFlowDirection.Horizontal;
ColorSpectrumStyle
:Change the Color Spectrum gradient style, with the rendering combination of base colors (Hue), or lighter colors (Tint) or darker colors (Shade).
Available Styles:
<controls:ColorPicker
x:Name="ColorPicker"
ColorSpectrumStyle="TintToHueToShadeStyle"
... >
</controls:ColorPicker>
ColorPicker.ColorSpectrumStyle =
Udara.Plugin.controls.ColorSpectrumStyle.TintToHueToShadeStyle;
PointerRingDiameterUnits
:Changes the Diameter size of the Pointer Ring on the Color Picker. It accepts values between 0 and 1, as a representation of numerical units which is compared to the 1/10th of the longest length of the Color Picker Canvas. By default this value is set to 0.6 units.
<controls:ColorPicker
x:Name="ColorPicker"
PointerRingDiameterUnits="0.6"
... >
</controls:ColorPicker>
ColorPicker.PointerRingDiameterUnits = 0.6;
PointerRingBorderUnits
:Changes the Border Thickness size of the Pointer Ring on the Color Picker. It accepts values between 0 and 1, as a representation of numerical units which is calculated against the diameter of the Pointer Ring. By default this value is set to 0.3 units.
<controls:ColorPicker
x:Name="ColorPicker"
PointerRingBorderUnits="0.3"
... >
</controls:ColorPicker>
ColorPicker.PointerRingBorderUnits = 0.3;
PointerRingPosition<X,Y>Units
:Changes the Pointer Ring’s position on the Color Picker Canvas programmatically. There are of two bindable properties PointerRingPositionXUnits and PointerRingPositionYUnits, which represents X and Y coordinates on the Color Picker Canvas. It accepts values between 0 and 1, as a presentation of numerical units which is calculated against the Color Picker Canvas’s actual pixel Width and Height. By default both the values are set to 0.5 units, which positions the Pointer Ring in the center of the Color Picker.
<controls:ColorPicker
x:Name="ColorPicker"
PointerRingPositionXUnits="0.3"
PointerRingPositionYUnits="0.7"
... >
</controls:ColorPicker>
ColorPicker.PointerRingPositionXUnits = 0.3;
ColorPicker.PointerRingPositionYUnits = 0.7;
Fires every time when the selected Color is changed
PickedColorChanged
:Gets the pickedColor, object type of Color
<controls:ColorPickerControl
x:Name="ColorPicker"
PickedColorChanged="ColorPicker_PickedColorChanged" />
ColorPicker.PickedColorChanged += ColorPicker_PickedColorChanged;
private void ColorPicker_PickedColorChanged(object sender, Color colorPicked)
{
//Do whatever you want with the colorPicker
}
since the control is just a ContentView
it can be customized in many ways - this is an example of a Clip
applied to the color picker.
https://user-images.githubusercontent.com/3210391/190870180-a7851bc4-c0f1-4b60-8212-b9668aebe091.mp4