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

programmatically set binding

6 Answers 493 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 08 Nov 2011, 09:50 PM
new to teleirk controls and tried searching elsewhere.

I have a radchart on a wpf app. the data series are dynamically given to the xaml file to display. it can chart 1 to 4 lines at a time. We want to create some toggles on the screen that will turn on/off viislibty PEr line and on/off data labels per line. 

i did some research on how to programmatically set binding and it only partially works. my converter fires from the toggle, but the dependency property does not. here are the key pieces of code:

codebehind:

Format Code Block
             var seriesMapping = new SeriesMapping();

            var seriesDefinition = new LineSeriesDefinition();

            seriesMapping.SeriesDefinition = seriesDefinition;

  var binding = new Binding(){ Path= new PropertyPath("IsChecked"), Converter = new BooleanToVisibilityConverter(), Source = toggleVisible1, Mode = BindingMode.OneWay};

                    BindingOperations.SetBinding(seriesDefinition, SeriesDefinition.VisibilityProperty, binding);
Format Code Block


XAML
<CheckBox x:Name="toggleVisible1" Content="Show Line"  HorizontalAlignment="Right" Margin="5,2,15,2" FlowDirection="RightToLeft" IsChecked="True"  />

converter code - for the most part boils down to this:
 return (value? Visibility.Visible : Visibility.Collapsed);


Again, the converter fires when the checkbox is toggle, but the series always stays visible. what am i doing wrong?
i am using latest version of wpf controls.

 

6 Answers, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 08 Nov 2011, 11:48 PM
Why are you setting your binding in code?

I always have trouble when I set binding in code. Even if it works it usually gets messy.
0
Robert
Top achievements
Rank 1
answered on 09 Nov 2011, 12:14 AM
You have got to admit, searching problems and finding that as a reply (why do you want to do that) is very unhelpful. Number one, it should work.

Again, what ocding am I missing.
0
Eric
Top achievements
Rank 1
answered on 09 Nov 2011, 01:09 AM
If you explain what you're trying to do, I can probably help you accomplish what you need while setting your bindings in XAML.

Or, you can found out why I don't do programmatic bindings for yourself.
0
Robert
Top achievements
Rank 1
answered on 09 Nov 2011, 07:15 PM
i was dynamically creating the seriesMapping and adding to radchart. I wanted to dynamically create the checkboxes that would toggle the visiblity and data label display per each series.

I have a set limit of 4 lines we will chart and i could hard code 4 seriesmappings and 4 groupings of checkboxes, i was going to do it dynamically.


But i needed to dynamically and programmatically link the seriesmapping (series defn.visiblity and data labels) dynamically created with the dynamically created checkboxes.

thus, that is why i wanted to do programmatically data binding and not hardcoding the 4 series and checkbox groups.
0
Eric
Top achievements
Rank 1
answered on 10 Nov 2011, 07:15 PM
The way I would work with that kind of data is to have an ObservableCollection of the item you'd like to plot in my DataContext. You could then have A listbox templated as a horizontal stack panel with a checkbox for the item template and databind it to your ObservableCollection.

Then I would make a style template for the series mappings and databind your SeriesMappings collection to the same observablecollection that your checkboxes are bound to.
0
Accepted
Evgenia
Telerik team
answered on 14 Nov 2011, 10:51 AM
Hello,

I suggest that you review this online example where the same scenario was demonstrated.
The checkboxes were added in the Legend via retemplating the default Legend Style. The full source code may be found under your local installation path of RadControls (for example C:\Program Files\Telerik\RadControls for WPF Q2 2011\Demos).

All the best,
Evgenia
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Chart
Asked by
Robert
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or