This project has moved and is read-only. For the latest updates, please go here.

How to set the title for LayoutAnchorable from MVVM binding?

Mar 16, 2016 at 2:31 PM
Edited Mar 16, 2016 at 2:32 PM
I am trying to set the title for LayoutAnchorable using binding. But its not working. Am I doing anything wrong?
<xcad:DockingManager x:Name="DockingManager"
                     AllowMixedOrientation="True">
    <xcad:LayoutRoot x:Name="LayoutRoot">
        <xcad:LayoutPanel Orientation="Horizontal">
            <xcad:LayoutAnchorablePaneGroup DockWidth="3*" Orientation="Vertical">
                <xcad:LayoutAnchorablePaneGroup>
                    <xcad:LayoutAnchorablePane DockHeight="*">
                        <xcad:LayoutAnchorable Title="{Binding TitleToBeDisplayed}"
                                               AutoHideHeight="240"
                                               CanClose="False"
                                               CanHide="False">
                        </xcad:LayoutAnchorable>
                    </xcad:LayoutAnchorablePane>
                    <xcad:LayoutAnchorablePane DockHeight="*">
                        <xcad:LayoutAnchorable Title="{Binding TitleToBeDisplayed1}"
                                               AutoHideHeight="240"
                                               CanClose="False"
                                               CanHide="False">
                        </xcad:LayoutAnchorable>
                    </xcad:LayoutAnchorablePane>
            </xcad:LayoutAnchorablePaneGroup>
        </xcad:LayoutPanel>
    </xcad:LayoutRoot>
</xcad:DockingManager>
Apr 1, 2016 at 8:48 PM
Hi,

Unfortunately, the LayoutAnchorable is not part of the VisualTree, since a LayoutAnchorableControl will be created from it. But you can add a proxy which uses binding :
  <StackPanel>
      <StackPanel.Resources>
            <FrameworkElement x:Key="ProxyElement"
                              DataContext="{Binding}" />
      </StackPanel.Resources>

      <ContentControl Visibility="Collapsed"
                      Content="{StaticResource ProxyElement}" />
      
      <xcad:DockingManager x:Name="DockingManager"
                           AllowMixedOrientation="True">
         <xcad:LayoutRoot x:Name="LayoutRoot">
            <xcad:LayoutPanel Orientation="Horizontal">
               <xcad:LayoutAnchorablePaneGroup DockWidth="3*"
                                               Orientation="Vertical">
                  <xcad:LayoutAnchorablePane DockHeight="*">
                     <xcad:LayoutAnchorable Title="{Binding DataContext.TitleToBeDisplayed, Source={StaticResource ProxyElement}}"
                                            AutoHideHeight="240"
                                            CanClose="False"
                                            CanHide="False">
                        <Button Content="TEST"/>
                     </xcad:LayoutAnchorable>
                  </xcad:LayoutAnchorablePane>
                  <xcad:LayoutAnchorablePane DockHeight="*">
                     <xcad:LayoutAnchorable Title="{Binding DataContext.TitleToBeDisplayed1, Source={StaticResource ProxyElement}}"
                                            AutoHideHeight="240"
                                            CanClose="False"
                                            CanHide="False">
                        <Button Content="TEST2" />
                     </xcad:LayoutAnchorable>
                  </xcad:LayoutAnchorablePane>
               </xcad:LayoutAnchorablePaneGroup>
            </xcad:LayoutPanel>
         </xcad:LayoutRoot>
      </xcad:DockingManager>
   </StackPanel>
And make sure to set the DataContext of the MainWindow to the control containing the the bounded properties :
this.DataContext = this;
Marked as answer by rmsh197 on 4/4/2016 at 2:49 AM
Apr 4, 2016 at 10:49 AM
Hi,

Thanks. Its working perfectly!