Articles in this section
Category / Section

How to bind underlying model property to Chart's behavior property?

2 mins read

This article describes the process of binding of binding a ViewModel property to a behavior property in a WPF Chart.

By default, WPF Chart behaviors are derived from DependencyObject. Meaning the DataContext is not automatically set for these behavior classes. However, you can bind a ViewModel property to a Chart behavior property by specifying the ViewModel as the source.

The following code samples demonstrate how to bind the view model property to the Chart behavior property.

XAML:

<Grid>
    <Grid.Resources>
        <local:ViewModel x:Key="viewModel"/>
    </Grid.Resources>
    <chart:SfChart>
        <chart:SfChart.Behaviors>
            <chart:ChartZoomPanBehavior EnableZoomingToolBar="{Binding EnableZoomingToolBar,Source={StaticResource viewModel} }"   />
        </chart:SfChart.Behaviors>
    </chart:SfChart>
 </Grid>

 

C#:

public class ViewModel : INotifyPropertyChanged
{
    private bool enableZoomingToolBar = true;
    public bool EnableZoomingToolBar
    {
       get
       {
        return enableZoomingToolBar;
       }
       set
       {
        enableZoomingToolBar = value;
        OnPropertyChanged("EnableZoomingToolBar");
       }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    private void OnPropertyChanged(string propertyName)
    {
      if (PropertyChanged != null)
      {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
    }
}

 

Conclusion

I hope you enjoyed learning about how to bind underlying model property to chart's behavior property.

You can refer to our WPF Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Charts documentation to understand how to present and manipulate data.


For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our WPF Chart and other WPF components.


If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied