programmatically set binding

7 posts, 1 answers
  1. Robert
    Robert avatar
    56 posts
    Member since:
    Sep 2011

    Posted 08 Nov 2011 Link to this post

    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.

     

  2. Eric
    Eric avatar
    14 posts
    Member since:
    Jun 2012

    Posted 08 Nov 2011 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    56 posts
    Member since:
    Sep 2011

    Posted 08 Nov 2011 Link to this post

    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.
  5. Eric
    Eric avatar
    14 posts
    Member since:
    Jun 2012

    Posted 08 Nov 2011 Link to this post

    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.
  6. Robert
    Robert avatar
    56 posts
    Member since:
    Sep 2011

    Posted 09 Nov 2011 Link to this post

    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.
  7. Eric
    Eric avatar
    14 posts
    Member since:
    Jun 2012

    Posted 10 Nov 2011 Link to this post

    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.
  8. Answer
    Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 14 Nov 2011 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready