Radial Gradients
This sample uses the CommunityToolkit.Mvvm package
and C# 14 partial properties: C# 14 is the default with the .NET 10 SDK, on older target frameworks set
<LangVersion>14</LangVersion>. You can learn more about the samples
here.
View Model
namespace ViewModelsSamples.Design.RadialGradients;
public class ViewModel
{
public double[] MariaValues { get; set; } = [7];
public double[] CharlesValues { get; set; } = [3];
}
XAML
<UserControl
x:Class="WPFSample.Design.RadialGradients.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
xmlns:vms="clr-namespace:ViewModelsSamples.Design.RadialGradients;assembly=ViewModelsSamples">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<!--
Use the RadialGradientPaint extension to create a circular gradients.
The Colors property accepts a string with the colors separated by a comma.
The Center property accepts a string with the coordinates separated by a comma,
both values are between 0 and 1, where 0,0 is the top left corner and 1,1 is the bottom right corner,
default is 0.5,0.5.
The ColorPositions property accepts a string with the color positions separated by a comma,
the positions are between 0 and 1, where 0 is the start of the gradient and 1 is the end of the gradient,
this defines the distribution of the colors in the gradient, use null to use the default distribution.
The TileMode property defines how the gradient is repeated.
-->
<lvc:PieChart LegendPosition="Right">
<lvc:PieChart.Series>
<lvc:SeriesCollection>
<lvc:XamlPieSeries
SeriesName="Maria"
Values="{Binding MariaValues}"
Pushout="10"
OuterRadiusOffset="20"
Fill="{lvc:RadialGradientPaint Colors='#B3E5FC, #01579B'}"/>
<lvc:XamlPieSeries
SeriesName="Charles"
Values="{Binding CharlesValues}"
Fill="{lvc:RadialGradientPaint Colors='#FFCDD2, #B71C1C'}"/>
</lvc:SeriesCollection>
</lvc:PieChart.Series>
</lvc:PieChart>
</UserControl>
~/samples/design/radialGradients/template.md