Jump to content
Software FX Community

ConditionalAttributes not refreshing after changing data


Recommended Posts

Dear Forum,

i have a Bar (gantt) chart with conditional attributes to show negative bars in red. This works fine but when I update my data even if the bar are updates (for example one bar became from negative to positive) the conditional colours are not reapplied so it stays red even if it is positive.

 Any idea about this? is this a bug?


Link to comment
Share on other sites

Hi JuanC,

here a part of our code on how we do this:

XAML: <Cfx:Chart x:Name="WidgetChart" ItemsSource="{Binding Path=ReportData, Mode=OneWay}">

C#:public IList<ChartableReportRow> ReportData   {   get { return _reportData; }   private set   {   _reportData = value;   NotifyPropertyChanged(() => this.ReportData);   }   }

and to set it I do:

this.ReportData = new Collection<ChartableReportRow>(   (from row in reportList select new ChartableReportRow(row)).ToList()   );

so it should be a new IList every time...

Link to comment
Share on other sites

  • 3 months later...

Hi JuanC,

Here how I ahve soleved the problem, I hope this will help others in the futute:

I have an attached property on cfx:Chart binfing to my data source, every time I update the data source I call Chart.ConditonalAttributes.Recalculate.

This make the trick and works fie (for my case):

public static class ConditionalAttributesFix   {   #region Fix on ItemsSource change   /// <summary>   /// Gets the attached dependency property used to apply the fix   /// </summary>   public static readonly DependencyProperty OnItemsSourceChangeProperty =   DependencyProperty.RegisterAttached(   "OnItemsSourceChange",   typeof(IEnumerable),   typeof(ConditionalAttributesFix),   new UIPropertyMetadata(null, OnOnItemsSourceChangePropertyChanged)   );

  /// <summary>   /// Gets the attached dependency property value used to apply the fix   /// </summary>   public static IEnumerable GetOnItemsSourceChange(DependencyObject obj)   {   Contract.Requires(obj != null);

  var obj_tmp = obj.GetValue(OnItemsSourceChangeProperty);   if (obj_tmp == null)   throw new InvalidOperationException("Dependency object value must not be null");

  return (IEnumerable)obj_tmp;   }

  /// <summary>   /// Sets the attached dependency property value used to apply fix   /// </summary>   public static void SetOnItemsSourceChange(DependencyObject obj, IEnumerable value)   {   Contract.Requires(obj != null);

  obj.SetValue(OnItemsSourceChangeProperty, value);   }

  static void OnOnItemsSourceChangePropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs args)   {   if (dpo == null)   return;

  Chart el = dpo as Chart;

  if (el == null)   throw new InvalidCastException("Object of type \"Chart\" expected");

  if (args.NewValue != null)   {   el.ConditionalAttributes.Recalculate();   }   }   #endregion   }}


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.

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