Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
XamDataChart CategoryDateTimeAxis out of sync
posted

Below are 2 snippets of code for the VM that builds the chart, and the VM that applies the data to show the chart:

The Chart VM:

if (axisVm is CategoryDateTimeXAxisVM)

                {

                    CategoryDateTimeXAxisVM vm = (CategoryDateTimeXAxisVM) axisVm;

                    CategoryDateTimeXAxis categoryDateTimeAxis = new CategoryDateTimeXAxis();

                    categoryDateTimeAxis.Label = vm.Label;

                    categoryDateTimeAxis.DateTimeMemberPath = vm.DateTimeMemberPath;

                    categoryDateTimeAxis.MinimumValue = DateTime.Now.AddYears(-50);

                    categoryDateTimeAxis.MaximumValue = DateTime.Now;

 

                    //BindingOperations.SetBinding(categoryDateTimeAxis, CategoryDateTimeXAxisVM.MinimumDateTimeProperty,

                    //                                   new Binding("MinimumDateTime") { Source = vm, Mode = BindingMode.TwoWay });

 

                    //BindingOperations.SetBinding(categoryDateTimeAxis, CategoryDateTimeXAxisVM.MaximumDateTimeProperty,

                    //                                   new Binding("MaximumDateTime") { Source = vm, Mode = BindingMode.TwoWay });

 

                    axis = categoryDateTimeAxis;

 

                    BindingOperations.SetBinding(axis, CategoryAxisBase.ItemsSourceProperty,

                        new Binding("Rows") {Source = chartVm});

 

                    axis.LabelSettings = new AxisLabelSettings

                    {

                        Location = xAxis++ % 2 == 0

                            ? AxisLabelsLocation.OutsideBottom

                            : AxisLabelsLocation.OutsideTop,

                        Visibility = Visibility.Collapsed

                    };

 

                    if (xAxis == 1)

                        axis.LabelSettings.Visibility = Visibility.Visible;

                }

 

The VM tied to the View

if (earliest != null)

                    {

                        if (earliest.MonthDate != null)

                        {

                            DateTime dt = earliest.MonthDate.Value;

 

                            DatumTimeChart.X1.MinimumDateTime = dt;

                            //DatumTimeChart.X2.MinimumDateTime = dt;

                        }

                    }

 

The commented out bindging in the first code snipped causes all the axes lines to appear, and possibly be out of sync.  The way it shows (the uncommented sections) it works.  It should be noted that the second snipped is in an asyn method and has to be due to the amount of data.

 

Any suggestions on how to bind the value of the Min/Max axes values when called?

Parents
  • 34510
    Verified Answer
    Offline posted

    Hi Keicha,

    The only thing I see weird about the binding code is the second parameter for SetBinding.  The second parameter is supposed to be a DependencyProperty present in the first parameter.  The first parameter is currently set to the CategoryDateTimeXAxis but the second parameter used is a DependencyProperty on CategoryDateTimeXAxisVM.  You should change the SetBinding method to be: 

    BindingOperations.SetBinding(categoryDateTimeAxis,
        CategoryDateTimeXAxis.MinimumValueProperty,
        new Binding("MinimumDateTime") { Source = vm, Mode = BindingMode.TwoWay });
    
    BindingOperations.SetBinding(categoryDateTimeAxis,
        CategoryDateTimeXAxis.MaximumValueProperty,
        new Binding("MaximumDateTime") { Source = vm, Mode = BindingMode.TwoWay });

     

    Other than that, everything looks fine.  I created a sample which used code similar to yours for the binding and it appears to be working properly.  I added a button to my UI that when pressed will add a day to the MaximumDateTime property in the VM.  When I press it I can see the chart updating accordingly.

    DataChartDateTimeAxisBinding.zip
Reply Children
No Data