C1FlexChart - Having binding issue with AxisStyle.Stroke and other properties

Posted by: digiptechnologies on 12 June 2019, 8:48 pm EST

    • Post Options:
    • Link

    Posted 12 June 2019, 8:48 pm EST

    Hello Support,

    We are evaluating flex chart component for our enterprise level WPF based application.

    We have a requirement, where end user can change properties of charts from the UI. And hence we need to bind some of the FlexChart controls properties like AxisX.Style.Stroke, AxisY.Style.Stroke, AxisX.Style.StrokeThickness, AxisX.MajorGridStyle.StrokeThickness etc… But some how that is not working as expected.

    After searching on the net I found one old post regarding this issue : https://www.grapecity.com/forums/silverlight-edition/binding-scale-and-value-of

    Though it is mentioned into that the binding is supported but seems not working with me. I have prepare a demo project to showcase the issue.

    Would you please go through it and let me know what changes I need to make for binding to work.

    Looking forward to hearing back from you.

    Thanks,

    Parthiv

  • Posted 12 June 2019, 8:58 pm EST

    Not able to upload the demo project zip file here even though it is 1MB, I have uploaded the demo code at:

    https://www.dropbox.com/s/lh9xg884pe5ij79/FlexChartDemo1.zip?dl=0

    Kindly review it and let me know your feedback.

  • Posted 13 June 2019, 4:56 am EST

    Hi,

    Axes in FlexChart are not FrameworkElements and hence don’t inherit the DataContext from their parent. So, In order to make the Binding work on Axis level, we have to provide the Source for Binding explicitly. This can be done by using a custom Freezable object as follows:

    public class BindingProxy : Freezable
    {
     protected override Freezable CreateInstanceCore()
     {
      return new BindingProxy();
     }
     public object Source
     {
      get
      {
       return GetValue(SourceProperty);
      }
      set
      {
       SetValue(SourceProperty, value);
      }
     }
     public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(object), typeof(BindingProxy), new UIPropertyMetadata());
    }
    
    

    And then use this for Binding on Axis.Style properties as follows:

    <local:FlexChart.Resources>
     <local:BindingProxy x:Key="bindingProxy" Source="{Binding}" />
    </local:FlexChart.Resources>
    <local:FlexChart.AxisX >
     <c1:Axis MajorGrid="True" AxisLine="True" >
      <c1:Axis.Style>
       <c1:ChartStyle Stroke="{Binding Source.AxisStroke, Source={StaticResource bindingProxy}, Mode=TwoWay}"
       		  StrokeDashArray="10 7"
                      StrokeThickness="{Binding Source.AxisThickness, Source={StaticResource bindingProxy}, Mode=TwoWay}"/>
      </c1:Axis.Style>
     </c1:Axis>
    </local:FlexChart.AxisX>
    

    Also, since ChartStyle does not implement INotifyPropertyChanged so, for any style property changes to be rendered immediately we have to force the FlexChart to re-render. For this we can have a property (say IsDirty) in our ViewModel and then use this for re-rendering FlexChart as follows:

    public bool IsDirty
    {
     get { return _isDirty; }
     set
     {
      if (_isDirty != value)
      {
       _isDirty = value;
       RaisePropertyChanged(nameof(IsDirty));
      }
     }
    }
    
    protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null)
    {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     if(propertyName == nameof(AxisThickness) || propertyName == nameof(AxisStroke))
     {
      IsDirty = true;
     }
    }
    

    Use this with FlexChart as follows:

    <local:FlexChart x:Name="flexChart" 
    	Tag="{Binding IsDirty, NotifyOnTargetUpdated=True}" TargetUpdated="FlexChart_TargetUpdated"/>
    
    
    private void FlexChart_TargetUpdated(object sender, DataTransferEventArgs e)
    {
     if ((Boolean)flexChart.Tag)
     {
      flexChartViewModel.IsDirty = false;
      flexChart.BeginUpdate();
      flexChart.EndUpdate();
     }
    }
    
    

    Please refer the attached modified sample (prj_FlexChartBindings.zip) to verify the same.

    Thanks,

    Basant

    prj_FlexChartBindings.zip

  • Posted 13 June 2019, 4:39 pm EST

    Thanks Basant for your response.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels