Databound Series ItemSource Not Updating

3 posts, 0 answers
  1. Christopher
    Christopher avatar
    5 posts
    Member since:
    Aug 2012

    Posted 09 Jan 2013 Link to this post

    Here is the xaml:
    <UserControl x:Class="Example.ScatterPlotPanel"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Exponent.Sensor.Pet.Analysis"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             x:Name="_this"
                 >
        <Grid>
            <telerik:RadPolarChart x:Name="chart" StartAngle="90">
                <telerik:RadPolarChart.Grid>
                    <telerik:PolarChartGrid GridLineVisibility="Both" StripesVisibility="Radial">
                        <telerik:PolarChartGrid.RadialStripeBrushes>
                            <SolidColorBrush Color="#FFD7D7D7" Opacity="0.3" />
                            <SolidColorBrush Color="Transparent" />
                        </telerik:PolarChartGrid.RadialStripeBrushes>
                    </telerik:PolarChartGrid>
                </telerik:RadPolarChart.Grid>
      
                <telerik:RadPolarChart.RadialAxis>
                    <telerik:NumericRadialAxis ShowLabels="False" />
                </telerik:RadPolarChart.RadialAxis>
      
                <telerik:RadPolarChart.PolarAxis>
                    <telerik:PolarAxis Minimum="0" />
                </telerik:RadPolarChart.PolarAxis>
                  
                <telerik:RadPolarChart.Series>
                    <telerik:PolarPointSeries x:Name="series" ItemsSource="{Binding ElementName=_this, Path=DataPoints}" AngleBinding="MissAngleDegrees" ValueBinding="MissDistanceMeters">
                        <telerik:PolarPointSeries.PointTemplate>
                            <DataTemplate>
                                <Ellipse Height="4" Width="4">
                                    <Ellipse.Style>
                                        <Style TargetType="Ellipse">
                                            <Setter Property="Fill" Value="Red"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Path=DataItem.IsHit}" Value="True">
                                                    <Setter Property="Fill" Value="Green"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Ellipse.Style>
                                </Ellipse>
                            </DataTemplate>
                        </telerik:PolarPointSeries.PointTemplate>
                    </telerik:PolarPointSeries>
                </telerik:RadPolarChart.Series>
            </telerik:RadPolarChart>
            <Button Content="Test" Click="OnUpdateDataPoints"/>
        </Grid>
    </local:AnalysisPanel>

    Here is the code behind:
    public class AlarmData
        {
            private double missDistance;
            private double missAngle;
            private bool isHit;
     
            public AlarmData()
            {
            }
     
            public AlarmData(bool isHit, double missDistance, double missAngle)
            {
                this.isHit = isHit;
                this.missDistance = missDistance;
                this.missAngle = missAngle;
            }
     
            public bool IsHit
            {
                get { return isHit; }
                set { isHit = value; }
            }
     
            public double MissDistanceMeters
            {
                get { return missDistance.Meters; }
            }
     
            public double MissAngleDegrees
            {
                get { return missAngle.Degrees; }
            }
        }
     
        public partial class ScatterPlotPanel : UserControl, INotifyPropertyChanged
        {
            private List<AlarmData> dataPoints = new List<AlarmData>();
     
            public event PropertyChangedEventHandler PropertyChanged;
     
            public ScatterPlotPanel()
            {
                InitializeComponent();
            }
     
            protected void OnPropertyChanged(string propertyName)
            {
                try
                {
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                    }
                }
                catch (Exception ex)
                {
                }
            }
     
            protected override void OnUpdateDataPoints(object sender, RoutedEventArgs e)
            {
                dataPoints.Clear();
     
                Random random = new Random();
                for (int i = 0; i < 100; i++)
                {
                    dataPoints.Add(new AlarmData(random.Next(0, 2) != 0, Distance.FromCentimeters(random.Next(0, 400)), Angle.FromDegrees(random.Next(0, 359))));
                }
     
                OnPropertyChanged("DataPoints");
            }
     
            public List<AlarmData> DataPoints
            {
                get { return dataPoints; }
            }
        }

    The problem is when I click the Test button in the example the series does not refresh. This is a simplified example of what we are trying to do but would like the ItemsSource property of the series to behave like it should and update if the binding changes. Any help on this issue is appreciated.
  2. Christopher
    Christopher avatar
    5 posts
    Member since:
    Aug 2012

    Posted 09 Jan 2013 Link to this post

    I should note that this code is a little incomplete because I whipped it up very fast. If you need a working example I can make one, but this should be very close. Also, I do not want to use an ObservableCollection so please do not suggest I use that. In our real application which is much more complicated we do not want to use an ObservableCollection.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Christopher
    Christopher avatar
    5 posts
    Member since:
    Aug 2012

    Posted 10 Jan 2013 Link to this post

    I actually figured this out myself. For WPF to recognize that the property did indeed change you have to do more than just dataPoints.Clear(). You must create a new dataPoints List. That solved the issue. Hope this helps someone else.
Back to Top