ToDxBrush()

View as Markdown

Definition

Converts a WPF Brush to a SharpDX Brush used for SharpDX rendering. Supports SolidColorBrush, LinearGradientBrush, and RadialGradientBrush types.

If you are using a large number of brushes, and are not tied to WPF resources, you should favor creating the SharpDX Brush directly since the ToDxBrush() method can lead to performance issues if called too frequently during a single render pass.

Method Return Value

A new SharpDX.Direct2D1.Brush constructed colors and brush properties of the WPF brush.

Syntax

DxExtensions.ToDxBrush(this System.Windows.Media.Brush brush, RenderTarget renderTarget)

\<wpfbrush\>.ToDxBrush(RenderTarget renderTarget)

Parameters

ParameterDescription
brushThe System.Windows.Media.Brush to convert
renderTargetThe RenderTarget associated with the brush resource

Examples

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "Example ToDXBrush";
6
7 // pushes the WPF brush to the UI for user to configure
8 TextBrush = System.Windows.Media.Brushes.DodgerBlue;
9 }
10}
11
12protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
13{
14 // convert user WPF selection to a DX brush
15 SharpDX.Direct2D1.Brush dxBrush = TextBrush.ToDxBrush(RenderTarget);
16
17 using (dxBrush)
18 {
19 RenderTarget.FillRectangle(new RectangleF(ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H), dxBrush);
20 }
21}
22
23// the WPF exposed to the UI which the user defines
24[XmlIgnore]
25public System.Windows.Media.Brush TextBrush { get; set; }
26
27[Browsable(false)]
28public string TextBrushSerialize
29{
30 get { return Serialize.BrushToString(TextBrush); }
31 set { TextBrush = Serialize.StringToBrush(value); }
32}