beltrams Posted July 3, 2012 Report Share Posted July 3, 2012 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? Thanks! Quote Link to comment Share on other sites More sharing options...
JuanC Posted July 3, 2012 Report Share Posted July 3, 2012 How are you updating your data? Are you setting ItemsSource again? Are you changing the underlying values using the same collection? Regards, JuanC Quote Link to comment Share on other sites More sharing options...
beltrams Posted July 3, 2012 Author Report Share Posted July 3, 2012 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... Quote Link to comment Share on other sites More sharing options...
beltrams Posted October 14, 2012 Author Report Share Posted October 14, 2012 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 }} Cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.