RadPanelBar and Binding

6 posts, 1 answers
  1. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 25 Apr 2009 Link to this post

    Hello

    I try to use the RadPanelBar with a Binding as ItemSource, but get an unexpected result. Without binding I would use it like this:
    <telerik:RadPanelBar> 
        <telerik:RadPanelBarItem> 
            <telerik:RadPanelBarItem.Header> 
                <Label Content="Header 1"/> 
            </telerik:RadPanelBarItem.Header> 
            <Label Content="Content 1"/> 
        </telerik:RadPanelBarItem> 
    </telerik:RadPanelBar> 

    That is no problem and looks exactly as expected. But as soon as I use it like this:
    <telerik:RadPanelBar Name="AttributeSetPanelBar" ItemsSource="{Binding}"
        <telerik:RadPanelBar.Resources> 
            <DataTemplate DataType="{x:Type wrp:AttributeSet}"
                <telerik:RadPanelBarItem> 
                    <telerik:RadPanelBarItem.Header> 
                        <Label Content="{Binding Name}"/> 
                    </telerik:RadPanelBarItem.Header> 
                    <Label Content="Content"/> 
                </telerik:RadPanelBarItem> 
            </DataTemplate> 
        </telerik:RadPanelBar.Resources> 
    </telerik:RadPanelBar> 
    and set it's DataContext to a List of objects (in this case AttributeSet), it changes its behaviour! Now the header includes the whole content, and the content itself (the secont Label) is also displayd as Header.
    Am I doing something wrong, or is this a bug?

    Regards
    Simon
  2. Answer
    Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 27 Apr 2009 Link to this post

    Hello Simon,

    If you want to use RadPanelBar with binding then you have to follow these steps:

    1.Define some ItemTemplate, e.g.:

    <core:HierarchicalDataTemplate x:Key="Entity" ItemsSource="{Binding Items}">
                    <TextBlock Text="{Binding Name}" Margin="5 2 5 2" />
     </core:HierarchicalDataTemplate>

    2.Avoid setting resources like in your example , it is better to set them in UserControl.Resources for example.

    3.Finally add the ItemsSource and ItemTemplate to RadPanelBar:

    <telerik:RadPanelBar BorderBrush="#9098a3" BorderThickness="1" Margin="5" x:Name="panelPab" ItemsSource="{StaticResource dsEntity}"
                    ItemTemplate="{StaticResource Entity}" />

    Please take a look at the following example:
    http://demos.telerik.com/silverlight/#PanelBar/DataBinding

    You can also take a look at this article:
    http://www.telerik.com/help/silverlight/radpanelbar-object-data.html

    Let me know if this helps.

    Best wishes,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Hi Boryana

    Thank you for your answer! As I can see, you are using a different HierarchicalDataTemplate from the namespace Telerik.Windows.Controls. I'm using the most actual version of the Telerik.Windows.Controls.dll (version 2009.1.312.35 for WPF), but it seems not to include the class HierarchicalDataTemplate. I searched throught all telerik dlls of my installation, but was not able to locate it. Is it possible, that it is just part of the Silverlight version?

    Regards
    Simon




  5. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Hi again

    OK, I got it now. Thank you for your help!

    Regards
    Simon
  6. Pedro
    Pedro avatar
    25 posts
    Member since:
    Aug 2010

    Posted 22 Nov 2010 Link to this post

    Hi,

    I have the same problem. I cant find the HierarchicalDataTemplate for WPF. What is the namespace?

    Best regards,
    Gonçalo
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Nov 2010 Link to this post

    Hi Gonçalo,

    There is a built-in HierarchicalDataTemplate in WPF so you don't need to use any namespace for it. You can have a look at that for more info.

    All the best,
    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top
UI for WPF is Visual Studio 2017 Ready