How to bind ShowLabels in ScatterSeriesDescriptor.Style

6 posts, 1 answers
  1. Joel
    Joel avatar
    53 posts
    Member since:
    Sep 2013

    Posted 24 Mar 2015 Link to this post

               
    <telerik:RadCartesianChart.SeriesProvider>
        <telerik:ChartSeriesProvider Source="{Binding CieDatums, Mode=OneWay}">
            <telerik:ChartSeriesProvider.SeriesDescriptors>
                <telerik:ScatterSeriesDescriptor  ItemsSourcePath="Value" XValuePath="X" YValuePath="Y" CollectionIndex="0">
                    <telerik:ScatterSeriesDescriptor.Style>
                        <Style TargetType="telerik:ScatterPointSeries">
                            <Setter Property="RenderOptions" Value="{StaticResource renderOptions}" />
                            <Setter Property="ShowLabels" Value="{Binding IsShowLabel, Mode=OneWay}"/>
                            <Setter Property="PointSize" Value="5,5"/>
                        </Style>
                    </telerik:ScatterSeriesDescriptor.Style>
                </telerik:ScatterSeriesDescriptor>
            </telerik:ChartSeriesProvider.SeriesDescriptors>

    I have a check box which allow user to choose whether to display the point Label or not. The Binding IsShowLabel is not working. How can i bind the check box's IsChecked to the ShowLabels property?
  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 25 Mar 2015 Link to this post

    Hello Joel,

    Without you implementation I cannot be sure what is causing the issue, but at first glance it seems that the property is not updated because the binding's Mode is set to OneWay. Please try to set it to TwoWay and see if this works in your scenario.
    <Setter Property="ShowLabels" Value="{Binding IsShowLabel, Mode=TwoWay}"/>
    If this doesn't help, can you please prepare an isolated project that demonstrates the described functionality and send it over? This way I can test it and my side and investigate what is causing this.

    Regards,
    Martin
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Joel
    Joel avatar
    53 posts
    Member since:
    Sep 2013

    Posted 25 Mar 2015 Link to this post

    I am using Caliburn.Micro for my implementation. Telerik: 2015.1.225.40
    Setting TwoWay does not work either.
    I have attached the screenshot showing the effects of check & uncheck the checkbox. 

    This is the checkbox declared in the same View as the chart:
    <CheckBox Content="Show Label" IsChecked="{Binding IsShowLabel, Mode=TwoWay}" Margin="4" VerticalAlignment="Center" VerticalContentAlignment="Center"/>

    Then in the ViewModel, the IsShowLabel property is defined. 
    public bool IsShowLabel
    {
        get
        {
            return m_IsShowLabel;
        }
        set
        {
            m_IsShowLabel = value;
            NotifyOfPropertyChange(() => IsShowLabel);
        }
    }
  5. Answer
    Martin
    Admin
    Martin avatar
    1099 posts

    Posted 27 Mar 2015 Link to this post

    Hi Joel,

    Note that the DataContext in the Style of the ScatterSeriesDescriptor is the view model of the series. In other words the ShowLabels property's binding is looking for such property in the series' view models.

    I used your code to create a small project demonstrating hiding of the series' labels with a checkbox. Please give it a try and let me know if it works for you. Basically, I added a boolean property in the view model of the series and in the main view model of the window.
    public class MainViewModel : ViewModelBase
    {
        private bool showLabels;
        public bool ShowLabels
        {
            get
            {
                return this.showLabels;
            }
            set
            {
                if (this.showLabels != value)
                {
                    this.showLabels = value;                
                    OnPropertyChanged("ShowLabels");
                }
            }
        }
        // ......................
    }
     
    public class SeriesViewModel : ViewModelBase
    {
        private bool showLabels;
        public bool ShowLabels
        {
            get
            {
                return this.showLabels;
            }
            set
            {
                if (this.showLabels != value)
                {
                    this.showLabels = value;
                    
                    OnPropertyChanged("ShowLabels");
                }
            }
        }
        // ......................
    }
    The property indicates if the labels should be displayed or not. The property in the main view model is bound to the CheckBox's IsChecked property and inside its setter I iterate through the series' collection and set their ShowLabels property.

    Please give the project a try and let me know if it helps. 

    Regards,
    Martin
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  6. Joel
    Joel avatar
    53 posts
    Member since:
    Sep 2013

    Posted 29 Mar 2015 in reply to Martin Link to this post

    Hi Martin,
      Thanks for pointing out that the DataContext in the Style of the ScatterSeriesDescriptor is the view model of the series.
       I realize my issue is due to CieDatums being of type Dictionary & it is not "observable" by itself.
       I am relying on http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/ to declare CieDatums.
  7. Joel
    Joel avatar
    53 posts
    Member since:
    Sep 2013

    Posted 29 Mar 2015 in reply to Martin Link to this post

    Hi Martin,
      Thanks for pointing out that the DataContext in the Style of the ScatterSeriesDescriptor is the view model of the series.
       I realize my issue was due to CieDatums being of type Dictionary which is not "observable" by itself.
       I am relying on http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/ to declare CieDatums.
Back to Top
UI for WPF is Visual Studio 2017 Ready