Problems with a DockingPanesFactory when setting the DataContext in XAML

3 posts, 1 answers
  1. Eric
    Eric avatar
    13 posts
    Member since:
    Jun 2015

    Posted 29 Jun 2015 Link to this post

    We have an existing WPF application that uses a similar UI library to Telerik. We are considering moving to Telerik for many reasons but one is the MVVM support for the RadDocking control. I have been reading and creating some test code and I came across something odd.

    I am setting the DataContext of my View/Window using the following XAML.

     

    <Window ...>
     
        <Window.Resources>
            <vm:MainWindowViewModel x:Key="MainWindowViewModel />
        </Window.Resources>
     
        <Grid DataContext={StaticResource MainWindowViewModel}">
     
        </Grid>
     
    </Window>

    Inside the Grid I have a RadDocking that uses the DockingPanesFactory. When I set the DataContext in XMAL (shown above), and I put a break point in the AddPane override for the DockingPanesFactory, the radDocking.SplitItems has zero items the first time.  

    If I set the DataContext in the code-behind of the View/Window using the following…

    public MainWindow(){
        InitializeComponent();
        this.DataContext = new MainWindowViewModel();
    }

     …and now look at the AddPane override for the DockingPanesFactory then the radDociing.SplitItems does NOT contain zero items.

     So if I set the DataContext in XAML the Designer in Visual Studio shows the correct layout but at runtime it puts each RadPane in its own container but if I set the DataContext in code behind the Designer does not work at all but it looks as expected at runtime.

     Why does the DataContext of my View/Window have to be set in code-behind to get the DockingPanesFactory to work correctly at runtime?

     Thanks,

       -eric

  2. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 02 Jul 2015 Link to this post

    Hello Eric,

    In order to get it working correctly would need to define the custom DockingPanesFactory at the very end of the Docking definition:

    <telerik:RadDocking PanesSource="{Binding Panes}">
        <telerik:RadSplitContainer InitialPosition="DockedLeft">
            <telerik:RadPaneGroup  x:Name="LeftPaneGroup">
            </telerik:RadPaneGroup>
        </telerik:RadSplitContainer>
        <telerik:RadSplitContainer InitialPosition="DockedBottom">
            <telerik:RadPaneGroup x:Name="BottomPaneGroup">
            </telerik:RadPaneGroup>
        </telerik:RadSplitContainer>
        <telerik:RadDocking.DockingPanesFactory>
            <local:CustomDockingPanesFactory />
        </telerik:RadDocking.DockingPanesFactory>
    </telerik:RadDocking>

    This way everything will load at the correct moment.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    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. UI for WPF is Visual Studio 2017 Ready
  4. Eric
    Eric avatar
    13 posts
    Member since:
    Jun 2015

    Posted 02 Jul 2015 in reply to Kalin Link to this post

    Thank you very much for the reply. I can verify that your suggestion does correct the issue I am seeing. This might be a good addition to the help for the DockingPanesFactory class. Thanks.
Back to Top