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

How to bind ShowLabels in ScatterSeriesDescriptor.Style

5 Answers 128 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Iron
Joel asked on 24 Mar 2015, 01:07 PM
           
<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?

5 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 25 Mar 2015, 08:54 AM
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.

 
0
Joel
Top achievements
Rank 1
Iron
answered on 25 Mar 2015, 09:54 AM
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);
    }
}
0
Accepted
Martin Ivanov
Telerik team
answered on 27 Mar 2015, 02:20 PM
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.

 
0
Joel
Top achievements
Rank 1
Iron
answered on 30 Mar 2015, 01:37 AM
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.
0
Joel
Top achievements
Rank 1
Iron
answered on 30 Mar 2015, 01:39 AM
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.
Tags
ChartView
Asked by
Joel
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Joel
Top achievements
Rank 1
Iron
Share this question
or