1

Would anyone know why I get the following error for the Databinding I'm doing?

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=TerminalName; DataItem=null; target element is 'LayoutDocument' (HashCode=15290806); target property is 'Title' (type 'String')

The View:

<Window x:Class="Understanding.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Understanding"
        xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <local:MainViewModel x:Name="ViewModel"/>
    </Window.DataContext>
    <Grid>
        <xcad:DockingManager AllowMixedOrientation="True">
            <xcad:LayoutRoot x:Name="_layoutRoot">
                <xcad:LayoutPanel Orientation="Horizontal">
                    <xcad:LayoutDocumentPane ShowHeader="True">
                        <xcad:LayoutDocument ContentId="Terminal" Title="{Binding Path=TerminalName}" CanClose="True">
                            <TextBlock Text="This is an example"/>
                        </xcad:LayoutDocument>
                    </xcad:LayoutDocumentPane>
                </xcad:LayoutPanel>
            </xcad:LayoutRoot>
        </xcad:DockingManager>
    </Grid>
</Window>

The ViewModel:

public class MainViewModel : ViewModelBase
    {
        private string _terminalName = "Python";

        public MainViewModel()
        {

        }

        public string TerminalName
        {
            get { return _terminalName; }
            set { _terminalName = value; OnPropertyChanged(nameof(TerminalName)); }
        }
    }
jsanalytics
  • 13,058
  • 4
  • 22
  • 43
hhherby
  • 11
  • 3
  • The short answer is that `LayoutDocument` is not part of the **Visual Tree** and therefore does not inherit the `DataContext`. Look [HERE](http://stackoverflow.com/questions/7660967/wpf-error-cannot-find-governing-frameworkelement-for-target-element) for some _hacky_ workaround if you wish. – jsanalytics Sep 21 '16 at 21:58

0 Answers0