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

Simple filtering demo Visibility code behind binding

3 Answers 105 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Biruh MEKONNEN
Top achievements
Rank 1
Biruh MEKONNEN asked on 27 Jan 2011, 07:25 PM
Hi,

I took a look at your demo for simple filtering in a RadChart and I wanted to adapt this code to my needs.
In the xaml code of Example.xaml there is this line
<telerik:LineSeriesDefinition ItemLabelFormat="0.#" 
Visibility="{Binding Source={StaticResource ViewModel}, 
Path=SeriesEU27Visibility}" />

I guess it means that for each SeriesDefinition, you bind the Visibility attribute to a SeriesVisibility.

My problem is that I would like to do the same in code-behind because I create dynamically the SeriesDefinition (in code-behind as well).
In fact, what I wanted to do is first, to create a dictionnary<String,SeriesVisbility>.
Each time I create a SeriesMapping and the corresponding SeriesDefinition, I would add to the dictionnary an item with the legendLabel attribute (unique in my case) as a key and a SeriesVisibility as the value.

I would then bind in code-behind this SeriesVisibility to the attribute Visibility of the SeriesDefinition.
 
Finally, in the ChangeSeriesVisibility(object parameter) method of ExampleViewModel, I would directly access to the SeriesVisibility thanks to the legendLabel (which is the key of my dictionnary) and change it between collapsed and visible. Then, the corresponding series will be hidden or visible because it was "bound" to the changed SeriesVisibility.

I'm a beginner, so is there a solution to do something like that? This code is of course wrong...
            StackedBarSeriesDefinition sd = new StackedBarSeriesDefinition();
            SeriesVisibility sv = new SeriesVisibility();
            sv = SeriesVisibility.Visible;
            Binding bnd = new Binding();
            bnd.Source = sv;
            sd.SetBinding(StackedBarSeriesDefinition.VisibilityProperty, sv);
 
Thanks for everything.















3 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 01 Feb 2011, 11:04 AM
Hi Biruh MEKONNEN,

Please, find attached a sample application which demonstrates how to achieve the same functionality as in the demo Simple Filtering example in code behind.

Hope this helps.

Regards,
Nikolay
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Biruh MEKONNEN
Top achievements
Rank 1
answered on 01 Feb 2011, 02:22 PM
Thanks !!!

I've tried the solution with this version 2010.3.1314.1040.

Hovwever, I don't understand why it is not working...
In fact, every time I uncheck or check one of the 4 series,  the last one (Series 3, green one)  becomes visible or collapsed. It's not the corresponding series which is rendered...
 I've debugged a bit the code and the index is right (in checkbox_checked method). It really gives the good index.

So, it is really strange...


0
Biruh MEKONNEN
Top achievements
Rank 1
answered on 01 Feb 2011, 03:54 PM
Hi,

I've managed to run correctly your sample application after reinstalling telerik controls.
 
It's working!!!
 
However, in my application, it doesn't work... The Chart doesn't want to refresh after changing the visible attribute of one Series.
I have to create a new SeriesMapping, then add and remove it. Then the chart will be refreshed and the Series won't be displayed.
But after the checkbox is reset to true, so it won't be possible to do it like that.

So, is there a way to just refresh the UI of a chart without rebinding? I had a problem like that with the radGridView.


Edit: It's working now, I had a problem with a group descriptor.

Thanks for everything!
Tags
Chart
Asked by
Biruh MEKONNEN
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Biruh MEKONNEN
Top achievements
Rank 1
Share this question
or