Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从Silverlight中的TabItem内容绑定到TabItem DataContext_C#_Silverlight_Xaml_Tabcontrol_Tabitem - Fatal编程技术网

C# 无法从Silverlight中的TabItem内容绑定到TabItem DataContext

C# 无法从Silverlight中的TabItem内容绑定到TabItem DataContext,c#,silverlight,xaml,tabcontrol,tabitem,C#,Silverlight,Xaml,Tabcontrol,Tabitem,我有一个TabItem,它的DataContext设置为ViewModel。 标题设置为标题视图,内容设置为项目视图 但是,这个来自项目视图的绑定不起作用 <TextBox Margin="0" Grid.Column="0" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext

我有一个TabItem,它的DataContext设置为ViewModel。 标题设置为标题视图,内容设置为项目视图

但是,这个来自项目视图的绑定不起作用

<TextBox Margin="0" Grid.Column="0" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.SourceCode, Mode=TwoWay}"/>
然而,这种约束

<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.Name}"/>
它位于标题视图中,可以正常工作

我甚至尝试过将标题中的TextBlock放入项目中,并将内容设置为新的HeaderView。无论我尝试什么,我都无法使内容的绑定工作,即使标题绑定工作正常

有人能解释一下吗

根据请求首先添加项目的完整视图

<UserControl x:Class="IE.Intergration.JobBuilder.Views.TabbedJobs.TabbedJobItem"
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" 
    DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=New.TabbedJobs.TabbedJobItem}"
    >
<UserControl.Resources>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" >
    <Grid.ColumnDefinitions>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"  />
        <RowDefinition Height="40"/>
    </Grid.RowDefinitions> 
    <TextBox Margin="0" Grid.Column="0" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.SourceCode, Mode=TwoWay}"/>
    <StackPanel Grid.Column="0" Grid.Row="1" FlowDirection="LeftToRight" Orientation="Horizontal">
        <Button Content="Save" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Save}" /> 
    </StackPanel>
</Grid>
头球呢

<UserControl x:Class="IE.Intergration.JobBuilder.Views.TabbedJobs.TabbedJobItemHeader"
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
    DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=New.TabbedJobs.TabJobHeader}" 
    >

<Grid x:Name="LayoutRoot">
    <TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.Name}"/>
</Grid>

在VS的输出窗口中有任何绑定错误吗?在本地,它给出了我以前没有注意到的{Error:System.Exception:BindingExpression\u CannotFindAncestor}。但HeaderView中没有这样的错误。就像TabItem不是内容的父项一样。TabItem不是内容的父项。您可以查看,并看到TabItems进入TabPanel,例如TabPanelTop,内容进入ContentPresenter,它是边框的子项,而不是TabPanel。@b托尼-是的,就是这样。TabItem负责呈现选项卡(即标题),但不负责呈现内容。请添加TabControl声明。感谢VS的输出窗口中有任何绑定错误?在本地,它给出了我以前没有注意到的{Error:System.Exception:BindingExpression_CannotFindAncestor}。但HeaderView中没有这样的错误。就像TabItem不是内容的父项一样。TabItem不是内容的父项。您可以查看,并看到TabItems进入TabPanel,例如TabPanelTop,内容进入ContentPresenter,它是边框的子项,而不是TabPanel。@b托尼-是的,就是这样。TabItem负责呈现选项卡(即标题),但不负责呈现内容。请添加TabControl声明。谢谢