Jump to content
Software FX Community

Data binding issue? Point is not updated.


vladvm

Recommended Posts

Hello,

 

I have a pie chart bound to a observable collection of some data objects. Chart Series is bound to a property of this data object. When I add new object into collection chart gets updated, but when I change value of the property that is bound to the series - it is not reflected in the chart. Is it by design or just some oversight in the current version? Or there is another way to get the result I want?

Thank you!

 

Here is an example:

public class Venue : DependencyObject

{

  public Venue()   {   } 

  public static readonly DependencyProperty NameProperty =   DependencyProperty.Register("Name", typeof(string), typeof(Venue),   new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));   public string Name   {   get { return (string)GetValue(NameProperty); }   set { SetValue(NameProperty, value); }   }   public static readonly DependencyProperty PercentProperty =   DependencyProperty.Register("Percent", typeof(double), typeof(Venue),   new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender)));   public double Percent   {   get { return (double)GetValue(PercentProperty); }   set { SetValue(PercentProperty, value); }   }

 

<Window.Resources> <local:Venues x:Key="selectedVenues"/>

  </Window.Resources>

<Grid>

<ChartFX:Chart x:Name="distChart" Style="{DynamicResource chartStyle}" Background="LightGray" Gallery="Pie" ItemsSource="{Binding Source={StaticResource selectedVenues}}">   <ChartFX:SeriesAttributes BindingPath="Percent" >   </ChartFX:SeriesAttributes>   </ChartFX:Chart> </Grid>

Link to comment
Share on other sites

We currently keep track of object changes by supporting objects that expose the INotifyPropertyChanged interface but we do not support updates on DPs. You could make your app work by changing your data class as follows

public class Venue : INotifyPropertyChanged|{   private double _percent;

  public event PropertyChangedEventHandler PropertyChanged;

  protected void RaisePropertyChanged (string name)   {   if (PropertyChanged != null)   PropertyChanged(this, new PropertyChangedEventArgs(name));   }

  public double Percent   {   get { return _percent; }   set {   m_percent = value;   RaisePropertyChanged("Percent");   }   }}

Normally I would recommend supporting INotifyPropertyChanged in your data objects instead of making them DependencyObjects, specially if they will only be used as source of bindings as you may not need the additional perf cost of making them Dependency Objects.

That being said, other WPF controls such as listbox support changes in both ways so we will be adding support for DP changes in future builds.

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...