Simple filtering demo Visibility code behind binding

4 posts, 1 answers
  1. Biruh MEKONNEN
    Biruh MEKONNEN avatar
    23 posts
    Member since:
    Apr 2010

    Posted 27 Jan 2011 Link to this post


    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.

  2. Answer
    Nikolay avatar
    384 posts

    Posted 01 Feb 2011 Link to this post

    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.

    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft R3 2016 release webinar banner
  4. Biruh MEKONNEN
    Biruh MEKONNEN avatar
    23 posts
    Member since:
    Apr 2010

    Posted 01 Feb 2011 Link to this post

    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...

  5. Biruh MEKONNEN
    Biruh MEKONNEN avatar
    23 posts
    Member since:
    Apr 2010

    Posted 01 Feb 2011 Link to this post


    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!
Back to Top