Hi,
I have a requirement to validate i.e user dynamically change the stroke and stroke thickness of MajorGridLines of chart. I read through on documentation and I came across :
After reading it make sense, why binding is not working. So I have adopted the approach mentioned into that knowledgebase document. So after following that appoarch Stroke is working, but as soon as I try to update StrokeThickness, the whole chart stops working.
Here is the code of GridLineStyleBehavior class I have used, you can see that in OnSingleGridStrockChanged method, I am setting Stroke, StrokeThickness and StrokeDashArray properties. So when I tried to apply all three nothing worked but if i apply only stroke it worked as expected. Can you provide some direction for how to achieve the expected result.
using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using SciChart.Charting.Visuals;
using SciChart.Charting.Visuals.Axes;
namespace FinSysPlatform.Common.Charts.Behavior
{
public class GridLineStyleBehavior
{
private static ChartGridType _chartGridType;
private static SolidColorBrush _singleGridStrock;
private static Visibility _singleGridVisibility;
private static Thickness _singleGridStrockThickness;
#region DP SingleGridStrock
/// <summary>
/// SingleGridStrock
/// </summary>
public static readonly DependencyProperty SingleGridStrockProperty = DependencyProperty.RegisterAttached(
"SingleGridStrock", typeof(SolidColorBrush), typeof(GridLineStyleBehavior), new PropertyMetadata(Brushes.Black, OnSingleGridStrockChanged));
private static void OnSingleGridStrockChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is AxisBase axisBase))
{
throw new ArgumentException(@"unexpected object", nameof(d));
}
if (e.NewValue is SolidColorBrush color)
{
Style newStyle = new Style(typeof(Line));
newStyle.Setters.Add(new Setter(Line.StrokeProperty, e.NewValue));
newStyle.Setters.Add(new Setter(Line.StrokeThicknessProperty, 5));
newStyle.Setters.Add(new Setter(Line.StrokeDashArrayProperty, "1 0"));
axisBase.MajorGridLineStyle = newStyle;
}
}
public static void SetSingleGridStrock(DependencyObject element, SolidColorBrush value)
{
element.SetValue(SingleGridStrockProperty, value);
}
public static SolidColorBrush GetSingleGridStrock(DependencyObject element)
{
return (SolidColorBrush) element.GetValue(SingleGridStrockProperty);
}
#endregion
}
}
- Parthiv Prajapati asked 6 years ago
- last edited 6 years ago
- You must login to post comments
The problem is in your code here:
newStyle.Setters.Add(new Setter(Line.StrokeProperty, e.NewValue));
newStyle.Setters.Add(new Setter(Line.StrokeThicknessProperty, 5));
newStyle.Setters.Add(new Setter(Line.StrokeDashArrayProperty, "1 0"));
StrokeThickness expects type double and you are setting int
StrokeDashArray expects type DoubleCollection and you are setting string.
If you set these properties correctly the behaviour you have created will work.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 6 years ago
- You must login to post comments
Please login first to submit.