2017-09-29 4 views
-1
私はこのコードを持っている

DataTemplateを結合ディスプレイは何も

<GroupBox Style="{DynamicResource MaterialDesignCardGroupBox}" Grid.Row="0" Grid.Column="0" > 
    <Label Content="{Binding MatchController.Match.TeamHome}" /> 
    <GroupBox.HeaderTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <Image Height="32" Width="32" Source="{Binding MatchController.Match.TeamHomeShield}" /> 
       <Label Content="{Binding MatchController.Match.TeamHome}" /> 
       <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{StaticResource MaterialDesignSubheadingTextBlock}" Text="{Binding Match.TeamHome}"/> 
      </StackPanel> 
     </DataTemplate> 
    </GroupBox.HeaderTemplate> 
</GroupBox> 

あなたは私がグループボックス内のDataTemplateを持つヘッダーテンプレートを持って見ることができるように。奇妙なのはGroupBoxの外のLabelはTeamHomeの値を正しく表示しますが、DataTemplateのStackPanelの中​​には何も表示されず、バインディングも同じですか?人生の謎。

+0

MaterialDesignCardGroupBoxスタイルも表示できますか? – shadow32

+0

はxamlのマテリアルデザインです。https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/blob/master/MainDemo.Wpf/GroupBoxes.xaml – Vandehusend

+0

MaterialDesignCardGroupBoxスタイルを適用しないとどのように動作しますか?あなたのGroupBoxは何に囲まれていますか?私はそれが別のDataTemplateにあると思われます – shadow32

答えて

0

あなたのGroupBoxをデータソースにバインドする必要があります。その後、そのテンプレートで使用できるようになります。

<GroupBox Style="{DynamicResource MaterialDesignCardGroupBox}" 
       Grid.Row="0" 
       Grid.Column="0" 
       DataContext="{Binding MatchController}"> 
     <Label Content="{Binding MatchController.Match.TeamHome}" /> 
     <GroupBox.HeaderTemplate> 
      <DataTemplate> 
       <StackPanel Orientation="Horizontal"> 
        <Image Height="32" 
         Width="32" 
         Source="{Binding Match.TeamHomeShield}" /> 
        <Label Content="{Binding Match.TeamHome}" /> 
        <TextBlock Margin="8,0,0,0" 
          VerticalAlignment="Center" 
          Style="{StaticResource MaterialDesignSubheadingTextBlock}" 
          Text="{Binding Match.TeamHome}" /> 
       </StackPanel> 
      </DataTemplate> 
     </GroupBox.HeaderTemplate> 
     </GroupBox> 
+0

データボックスプロパティがグループボックスオブジェクトに見つかりません – Vandehusend

+0

これは誤植で、DataContextにする必要があります – shadow32

+0

Meac datacontext。今すぐ答えを修正する。 – Marisa

0
<DataTemplate> 
          <StackPanel Orientation="Horizontal"> 
           <Image Height="32" Width="32" Source="{Binding MatchController.Match.TeamHomeShield}" /> 
           <Label Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.MatchController.Match.TeamHome}" /> 
           <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{StaticResource MaterialDesignSubheadingTextBlock}" Text="{Binding Match.TeamHome}"/> 
          </StackPanel> 
         </DataTemplate> 
        </GroupBox.HeaderTemplate> 

あなたのコードのDataContextのは、ウィンドウの要素に設定されている場合は、このコードを使用します。それ以外の場合は、このDataContextを持つ最も近い要素の型に変更します。

+0

コマンドを配置する場所は? – Vandehusend

+0

申し訳ありません

+0

各コントロールのすべてのコンテンツを追加する必要があります。グループボックスでこれのようなもの?なぜなら、あなたのソリューションはうまくいくが、各コントロールのコードがあまりにも多いからです。 – Vandehusend

関連する問題