Jump to content
Software FX Community

How do you use a BrushConverter?


korthmat

Recommended Posts

On several of our charts, we'd like to have the bars drawn with a linear gradient, where we only need to specify the basic color.  The BrushConverter in ChartFX.WPF.Converters seems like it should be a perfect solution, but even after following the examples in the quickstart doc, I can't get it to work; tracing the bindings shows that the BrushConverter is always returning null.

 How is it that you're supposed to use the BrushConverter?

Link to comment
Share on other sites

  • 2 weeks later...

The following DataTemplate shows a couple of uses of a BrushConverter

<cfxConverters:BrushConverter x:Key="MyBrushConverter"/><DataTemplate x:Key="SimpleBar">   <Rectangle x:Name="Bar" Canvas.Left="{Binding Path=Left}" Canvas.Top="{Binding Path=Top}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Stroke="Black">   <Rectangle.Fill>   <!--   <Binding Path="Self" Converter="{StaticResource MyBrushConverter}" ConverterParameter="L,0,0,0,1,2,=,0,@0;-40,1" />   -->   <Binding Path="Self" Converter="{StaticResource MyBrushConverter}" ConverterParameter="L,0,0,0,1,2,=,0,#FF0000,1" />   </Rectangle.Fill>   </Rectangle>   <DataTemplate.Triggers>   <DataTrigger Binding="{Binding Path=Dimmed}"> <DataTrigger.Value>   <sys:Boolean>True</sys:Boolean>   </DataTrigger.Value>   <Setter Property="Opacity" Value="0.25" TargetName="Bar" />   </DataTrigger>   </DataTemplate.Triggers></DataTemplate>

Both converters share the following

L -> Linear Brush0,0,0,01 -> Linear Gradient StartPoint and EndPoint2 -> 2 Gradient Stops

What follows is as many gradient stops as needed, in the first sample (commented) we create a gradient that goes from the original color to a darker one using the HSV method

=,0 -> = Means use the base color and 0 is the gradient offset@0;-40,1 -> @ Means use HSV model, 0 means not affecting the saturation and -40 means substracting 40 from value. 1 is the gradient offset

The second one creates a gradient that goes from the original color to red

=,0 -> = Means use the base color and 0 is the gradient offset#FF0000, 1-> Means use Red and 1 is the gradient offset

Additionally BrushConverter also exposes HLS conversion (using the % character) or changing alphas. Please let me know if you need samples of these.

I apologize for the delay of this post, we have been very busy working out the bits for our go-live license.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...