How to bind RadPanelBar to View with graphics in WPF MVVM application.

3 posts, 1 answers
  1. Eugene
    Eugene avatar
    83 posts
    Member since:
    Jan 2016

    Posted 04 Feb 2016 Link to this post

    I have an WPF MVVM Catel project with five Views: View_1, View_2, View_3, View_4 and View_5. Each View is implemented as catel:UserControl and has appropriate Model and ViewModel. There is a telerik:RadCartesianChart presenting diagram changing in real time in each View. There is also a catel:Window in my application that is the application main window. There is RadPanelBar in the application main window XAML. This RadPanelBar has five instances of telerik:RadPanelBarItem in XAML. I'm in need of binding of each telerik:RadPanelBarItem to appropriate View. For example: first RadPanelBarItem to View_1, the second one to View_2 e.t.c. Please give me a reference to example of that binding. Thank you very much in advance.
  2. Answer
    Martin Ivanov
    Martin Ivanov avatar
    2515 posts

    Posted 08 Feb 2016 Link to this post

    Hello Eugene,

    RadPanelBar works with hierarchical data, which means that its RadPanelBarItems are not content controls but item controls. Therefore, in order to display a user control in a RadPanelBarItem you will need to add it in its Items collection. 

    In your case you can add the user controls with the chart using the following syntax:
        <local:View1 />
        <local:View2 />
    The equivalent for this declaration in code is the following:
    var panelBarItem1 = new RadPanelBarItem();
    var panelBarItem2 = new RadPanelBarItem(); 
    panelBarItem1.Items.Add(new View1());
    panelBarItem2.Items.Add(new View2());

    You can also consider using data binding to populate the panelbar with items. For example, you can store the viewmodels of the user controls into a collection and bind it to the ItemsSource of the panelbar control. Then define few DataTemplates with the different views (UserControls) and use DataTemplateSelector to decide which templates should be used depending on the items in the ItemsSource collection. You can also take a look at the RadPanelBar Data Binding demo.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Eugene
    Eugene avatar
    83 posts
    Member since:
    Jan 2016

    Posted 28 Mar 2016 in reply to Martin Ivanov Link to this post

    Thank you very much for your help.
Back to Top