This is a migrated thread and some comments may be shown as answers.

problem when changing Appearance colors

4 Answers 87 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 26 Jul 2010, 09:34 PM
Hello,

I'm currently building an application where the user has some control on how a chart looks.

Every property I'm changing work perfectly except for anything linked to a brush.

The different brushes the the SeriesAppearanceSettings are correctly updated till a Rebind() is called or till the ItemSource is changed when a color change has been previously called. From that point on an ArgumentException is thrown if I attempt to change a previously changed brush:
"The provided DependencyObject is not a context for this Freezable.
Parameter name: context"

here is my method for changing colors:
public void SetFillBrush(Brush color)
        {
            _lineDefinition1.Appearance.Stroke = color;
            _barDefinition1.Appearance.Fill = color;
            _areaDefinition1.Appearance.Fill = color;
 
            _lineDefinition2.Appearance.Stroke = color;
            _barDefinition2.Appearance.Fill = color;
            _areaDefinition2.Appearance.Fill = color;
        }


Any help is appreciated.

4 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 29 Jul 2010, 06:25 PM
Hi Julien,

Unfortunately we are unable to reproduce the problematic behavior based on the provided information. Please review the attached sample application that we prepared based on your guidelines and let us know how can we observe the erroneous issue.

Looking forward to your reply.


Kind regards,
Freddie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 30 Jul 2010, 04:45 PM
Well ATM it seems that I'm having a very hard time reproducing the exception in the solution you provided as well.

I've tried every possibilities and have yet to come up with something that trigger the exception. (changing mapping, changing definition, using definitions/mapping in private field, getting colors for a RadColorPaletteView, changing the ItemSource, making an outside object update the properties, using same brush instead of creating a new one for every definition)

Here is what the C# code looks like ATM, still trying to reproduce it to pinpoint what trigger the exception

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using Telerik.Windows.Controls.Charting;
using System.Collections.Generic;
using System.Windows.Media;
using Telerik.Windows.Controls;
 
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ChartAdaptor _adaptor;
 
        private ObservableCollection<ChartData> _data1;
        private ObservableCollection<ChartData> _data2;
 
        private bool _usingData1 = true;
 
        public MainWindow()
        {
            InitializeComponent();
 
            _adaptor = new ChartAdaptor(RadChart1);
 
            _data1 = new ObservableCollection<ChartData>();
            _data1.Add(new ChartData() { YValue = 21, YValue2 = 27 });
            _data1.Add(new ChartData() { YValue = 31, YValue2 = 14 });
            _data1.Add(new ChartData() { YValue = 11, YValue2 = 50 });
            _data1.Add(new ChartData() { YValue = 171, YValue2 = 65 });
            _data1.Add(new ChartData() { YValue = 25, YValue2 = 111 });
            _data1.Add(new ChartData() { YValue = 40, YValue2 = 3 });
 
            _data2 = new ObservableCollection<ChartData>();
            _data2.Add(new ChartData() { YValue = 5, YValue2 = 2001 });
            _data2.Add(new ChartData() { YValue = 8, YValue2 = 2154 });
            _data2.Add(new ChartData() { YValue = 11, YValue2 = 6546 });
            _data2.Add(new ChartData() { YValue = 1, YValue2 = 1254 });
            _data2.Add(new ChartData() { YValue = 2, YValue2 = 2115 });
            _data2.Add(new ChartData() { YValue = 20, YValue2 = 1201 });
 
             
            RadChart1.ItemsSource = _data1;
            RadChart1.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;
             
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            _adaptor.Rebind();
        }
 
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            _adaptor.ChangeMapping();
        }
 
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            _adaptor.ChangeDefinition();
        }
 
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (_usingData1)
            {
                RadChart1.ItemsSource = null;
                RadChart1.ItemsSource = _data2;
            }
            else
            {
                RadChart1.ItemsSource = null;
                RadChart1.ItemsSource = _data1;
            }
 
            _usingData1 = !_usingData1;
        }
 
        private void radColorPaletteView1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (radColorPaletteView1.SelectedItem != null)
            {
                _adaptor.SetColor(new SolidColorBrush((Color)radColorPaletteView1.SelectedItem));
            }
        }
    }
 
    public class ChartData : INotifyPropertyChanged
    {
        private double yValue;
        private double yValue2;
 
        public double YValue
        {
            get
            {
                return this.yValue;
            }
            set
            {
                if (this.yValue != value)
                {
                    this.yValue = value;
                    this.OnPropertyChanged(new PropertyChangedEventArgs("YValue"));
                }
            }
        }
 
        public double YValue2
        {
            get
            {
                return this.yValue2;
            }
            set
            {
                if (this.yValue2 != value)
                {
                    this.yValue2 = value;
                    this.OnPropertyChanged(new PropertyChangedEventArgs("YValue2"));
                }
            }
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        protected void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, args);
        }
 
    }
 
    public class ChartAdaptor
    {
        private RadChart _chart;
 
        private SeriesMapping _mapping1;
        private SeriesMapping _mapping2;
        private SeriesMapping _mapping12;
        private SeriesMapping _mapping22;
 
        private SeriesDefinition _def1;
        private SeriesDefinition _def12;
        private SeriesDefinition _def2;
        private SeriesDefinition _def22;
 
        bool _isSetup1 = true;
        bool _isMappingSetup1 = true;
 
        public ChartAdaptor(RadChart chart)
        {
            _chart = chart;
 
            _mapping1 = new SeriesMapping();
            _def1 = new LineSeriesDefinition();
            _mapping1.SeriesDefinition = _def1;
            this.UpdateSeriesColor(_def1, new SolidColorBrush(Colors.Lime));
            _mapping1.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
 
            _mapping2 = new SeriesMapping();
            _def2 = new BarSeriesDefinition();
            _mapping2.SeriesDefinition = _def2;
            this.UpdateSeriesColor(_def2, new SolidColorBrush(Colors.Lime));
            _mapping2.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
 
            _chart.SeriesMappings.Add(_mapping1);
            _chart.SeriesMappings.Add(_mapping2);
 
            _mapping12 = new SeriesMapping();
            _mapping12.SeriesDefinition = _def1;
            _mapping12.ItemMappings.Add(new ItemMapping("YValue2", DataPointMember.YValue));
 
            _mapping22 = new SeriesMapping();
            _mapping22.SeriesDefinition = _def2;
            _mapping22.ItemMappings.Add(new ItemMapping("YValue2", DataPointMember.YValue));
 
            _def12 = new StackedAreaSeriesDefinition();
            this.UpdateSeriesColor(_def12, new SolidColorBrush(Colors.Lime));
            _def22 = new StackedAreaSeriesDefinition();
            this.UpdateSeriesColor(_def12, new SolidColorBrush(Colors.Lime));
        }
         
        public void SetColor(Brush color)
        {
            UpdateSeriesColor(_def1, color);
            UpdateSeriesColor(_def2, color);
            UpdateSeriesColor(_def12, color);
            UpdateSeriesColor(_def22, color);
        }
 
        public void ChangeDefinition()
        {
            if (!_isSetup1)
            {
                _mapping1.SeriesDefinition = _def1;
                _mapping2.SeriesDefinition = _def2;
                _mapping12.SeriesDefinition = _def12;
                _mapping22.SeriesDefinition = _def22;
            }
            else
            {
                _mapping1.SeriesDefinition = _def12;
                _mapping2.SeriesDefinition = _def22;
                _mapping12.SeriesDefinition = _def1;
                _mapping22.SeriesDefinition = _def2;
            }
 
            Rebind();
 
            _isSetup1 = !_isSetup1;
        }
 
        public void ChangeMapping()
        {
            _chart.SeriesMappings.Clear();
 
            if (_isMappingSetup1)
            {
                _chart.SeriesMappings.Add(_mapping12);
                _chart.SeriesMappings.Add(_mapping22);
            }
            else
            {
                _chart.SeriesMappings.Add(_mapping1);
                _chart.SeriesMappings.Add(_mapping2);
            }
 
            _isMappingSetup1 = !_isMappingSetup1;
 
            Rebind();
        }
 
        private void UpdateSeriesColor(ISeriesDefinition definition, Brush brush)
        {
            definition.Appearance.Fill = brush;
            definition.Appearance.Stroke = brush;
        }
 
        public void Rebind()
        {
            _chart.Rebind();
        }
    }
}
0
Giuseppe
Telerik team
answered on 04 Aug 2010, 03:56 PM
Hi Julien,

Unfortunately we are still unable to reproduce the problematic behavior in our local tests as well -- please let us know if the issue resurfaces, so we can advise you properly how to proceed.


Regards,
Freddie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 04 Aug 2010, 07:09 PM
Thank you for the help

A small update, I've been catch argument exception and I've learned that WindowBase throws the exception, and that when catching the ArgumentException and proceeding as if nothing happened still updates the color as expected.
Tags
Chart
Asked by
Julien
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Julien
Top achievements
Rank 1
Share this question
or