Can't bind to EmptyContent

7 posts, 1 answers
  1. Lian
    Lian avatar
    12 posts
    Member since:
    Jan 2015

    Posted 28 Jan 2015 Link to this post

    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.
  2. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 02 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lian
    Lian avatar
    12 posts
    Member since:
    Jan 2015

    Posted 02 Feb 2015 in reply to Petar Marchev Link to this post

    Hi Petar,

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

    Many thanks,
    Lian
  5. Lian
    Lian avatar
    12 posts
    Member since:
    Jan 2015

    Posted 02 Feb 2015 Link to this post

    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.     
  6. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 03 Feb 2015 Link to this post

    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.

     
  7. Lian
    Lian avatar
    12 posts
    Member since:
    Jan 2015

    Posted 03 Feb 2015 in reply to Petar Marchev Link to this post

    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
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 04 Feb 2015 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready