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

Can't bind to EmptyContent

6 Answers 135 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Lian
Top achievements
Rank 2
Lian asked on 28 Jan 2015, 10:29 PM
As I know, in case of no data, the chart shows the text "No data to plot" by default.
ChartView provides 2 properties to customize the no data content and style, they are EmptyContent and EmptyContentTemplate.

The strange thing is - The chart still show the default text if its EmptyContent is bound to a view model property, but if the customized text is set to EmptyContent directly in xaml then it works well.

I made the same settings to VerticalAxis - bind Title and set TitleTemplate and didn't has this problem.

Any suggestion? Thank you.

6 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 02 Feb 2015, 09:24 AM
Hello Lian,

I created a simple project and I was able to reproduce the issue at hand. It appears that the chart has some internal logic for setting the EmptyContent property in case the EmptyContent is not set. This code is executed before the binding kicks in and since its set through the property setter, the value from the binding is not taken into consideration.

I am unsure if this is a flaw in the control or by design. Anyway, you can easily work this out with an attached property. The value of the attached property will be bound to the view model's property and in the event handler of the attached property you will set the EmptyContent property directly.

I will log this for an investigation so that we can determine if this is indeed a bug.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lian
Top achievements
Rank 2
answered on 02 Feb 2015, 07:14 PM
Hi Petar,

In my view it should look like a bug.
Anyway, I appreciate your helpful workaround solution.

Many thanks,
Lian
0
Lian
Top achievements
Rank 2
answered on 02 Feb 2015, 07:59 PM
Hi Petar,

I tried your solution as below, it works.

private static void EmptyContentTextPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
            var chart = d as RadCartesianChart;
            if (chart == null) return;

            chart.EmptyContent = e.NewValue;
}

But, the changes lead to another seemingly unrelated problem - Unexpectedly the registered vertical axis ActualRangeChanged event handler can't be triggered after the chart is loaded.
Once I removed the EmptyContentText attached property from the chart in xaml, then the ActualRangeChanged event handler returns to normal.

What's your view on that? Thanks.     
0
Petar Marchev
Telerik team
answered on 03 Feb 2015, 09:44 AM
Hi Lian,

There is no direct connection between the two. I created a simple project to test this. Everything works as expected. I am attaching this project so that you can test on your side. Let us know if you get different results.

During load, the ActualRangeChanged event is raised once, and upon the click of the button, the  event is properly raised again.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lian
Top achievements
Rank 2
answered on 03 Feb 2015, 10:05 PM
Hi Petar,

Thanks for your quick response.
I think you are right - there is no direct connection between them.

For your information, the root cause of my issue is - In some cases the chart ActualRangeChanged event handler won't be triggered if you registered it in the loaded event handler, it means sometimes the ActualRangeChanged event gets triggered already before hitting loaded event.

Many thanks,
Lian
0
Petar Marchev
Telerik team
answered on 04 Feb 2015, 08:50 AM
Hello Lian,

This is expected. If the ActualRange is already known the event will not be triggered. The actual range is determined by the axis during the update of the UI, but depending on the exact case (whether the chart is bound or not, and whether the bindings have kiccked in or not) the ActualRangeChanged event may  be triggered before or after the char has loaded. Let us know if you need more information.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ChartView
Asked by
Lian
Top achievements
Rank 2
Answers by
Petar Marchev
Telerik team
Lian
Top achievements
Rank 2
Share this question
or