RadPane DataTemplate and / or Binding when using DockingPanesFactory

1 Answer 28 Views
Docking
Jason
Top achievements
Rank 1
Jason asked on 30 Aug 2022, 04:17 AM

Hi

I'm trying to implement RadDocking using DockingPanesFactory as per your examples (like this one).

I have set the PaneSource to a collection of viewmodels e.g. MyViewModel which has a property "Name".

I would like to bind the RadPane header to the "Name" property on the viewmodel. Ideally I would like to have a custom DataTemplate as well but I will settle for just getting the value to update with the ViewModel.

The CreatePaneFromItem method states that "...set any of the DataContext, Header, Title or Content based on the item as well as Style with bindings in the style setters to bind properties of the item to properties of the RadPane" however nothing I've tried seems to work.

I've tried setting a style with the setter properties like this:

var pane = new RadPane();
pane.DataContext = (MyViewModel)item;

Style style = new Style();
style.TargetType = typeof(RadPane);
Setter setter = new Setter();
setter.Property = RadPane.HeaderProperty;
setter.Value = new Binding("Name")
pane.Style = style;

Ideally I'd like to define a DataTemplate in a ResourceDictionary and retrieve and set that to the pane header but I'm not sure how to get that resource in the DockingPanesFactory

Can you offer any advice?

Jason

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 01 Sep 2022, 04:03 PM

Hello Jason,

The custom DataTemplate for the HeaderTemplate property of the RadPane element could be defined in the Resources collection of the App.xaml file. Then, it could be retrieved as follows in the CreatePaneForItem method:

public class CustomPanesFactory : DockingPanesFactory
{
    protected override RadPane CreatePaneForItem(RadDocking radDocking, object item)
    {
        RadPane pane = new RadPane();
		
        DataTemplate dataTemplate = (DataTemplate)Application.Current.Resources["MyCustomHeaderTemplate"];

        pane.HeaderTemplate = dataTemplate;

        return pane;
    }
}

To bind a property from the underlying data object (MyViewModel in your scenario), the SetBinding property of the RadPane instance could be utilized.

public class CustomPanesFactory : DockingPanesFactory
{
    protected override RadPane CreatePaneForItem(RadDocking radDocking, object item)
    {
        MyViewModel myViewModel = (MyViewModel)item;
    
        RadPane pane = new RadPane() { DataContext = myViewModel };
    
        pane.SetBinding(RadPane.HeaderProperty, new Binding("Name"));
		
        return pane;
    }
}

With a simple DataTemplate for the HeaderTemplate property the following result will be present:

With this said, I have attached a sample project for you to test.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Docking
Asked by
Jason
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or