0

私の DataTemplate (ClosableTabItemTemplate) を Relative Source で HeaderedContentControl の Workspaces DataContext にバインドしたいと思います。残念ながらうまくいきませんか?何か案は?

ところで: 次のコマンド ライン エラーが発生します: System.Windows.Data Error: 40 : BindingExpression path error: 'DisplayName' プロパティが 'object' ''AllUserView' (Name='')' に見つかりません。BindingExpression:Path=DataContext.DisplayName; DataItem='TabItem' (Name=''); ターゲット要素は 'ContentPresenter' (Name='') です。ターゲット プロパティは「コンテンツ」(タイプ「オブジェクト」)

シア・マイケル

<HeaderedContentControl 
      Content="{Binding Path=Workspaces}"
      ContentTemplate="{StaticResource WorkspacesTemplate}"
      Header=""
      Style="{StaticResource MainHCCStyle}" DataContext="{Binding}" 
                />
<DataTemplate x:Key="ClosableTabItemTemplate">
    <DockPanel Width="120"  >
        <Button 
    Command="{Binding Path=DataContext.CloseCommand, RelativeSource={RelativeSource AncestorType={x:Type HeaderedContentControl}}}"
    Content="X"
    Cursor="Hand"
    DockPanel.Dock="Right"
    Focusable="False"
    FontFamily="Courier" 
    FontSize="9"
    FontWeight="Bold"  
    Margin="0,1,0,0"
    Padding="0"
    VerticalContentAlignment="Bottom"
    Width="16" Height="16" 
    />
    <ContentPresenter 
    Content="{Binding Path=DataContext.DisplayName, RelativeSource={RelativeSource AncestorType={x:Type HeaderedContentControl}}}" 
    VerticalAlignment="Center" 
    />
    </DockPanel>
</DataTemplate>

<DataTemplate x:Key="WorkspacesTemplate">
    <TabControl 
  IsSynchronizedWithCurrentItem="True" 
  ItemsSource="{Binding}"      
  ItemTemplate="{StaticResource ClosableTabItemTemplate}"
  Margin="4"
  />
</DataTemplate>
4

1 に答える 1

0

RelativeSource.AncestorLevel Propertyを使用する必要があると思います。デフォルトのレベルは 1 で、WorkspacesTemplateTabControlHeaderedContentControl同様です。試す

Content="{Binding Path=DataContext.DisplayName,
                  RelativeSource={RelativeSource AncestorType={x:Type HeaderedContentControl},
                                                 AncestorLevel=2}}" 

あなたの本当のを見つけるためにHeaderedContentControl

于 2012-07-21T16:52:24.127 に答える