2016-03-19 4 views
0

GridPanelTemplateとする必要があります。それは大きな問題ではないが、私はその他のコントロールを持っている必要があるGridあまりにも。ItemsPanelTemplateの問題

<ItemsControl x:Name="itemscontname" ItemsSource="{Binding Fields}" Grid.Column="0" 
       ItemsPanel="{StaticResource gridKey}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Button .../> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
    <ItemsControl.ItemContainerStyle> 
     <Style> 
      <Style.Setters> 
       <Setter Property="Grid.Row" Value="{Binding RowNumber}" /> 
       <Setter Property="Grid.Column" Value="{Binding ColumnNumber}" /> 
      </Style.Setters> 
     </Style> 
    </ItemsControl.ItemContainerStyle> 
</ItemsControl> 

そして、私のItemsPanelTemplate:だから私のItemsControlには、次のようになります

<ItemsPanelTemplate x:Key="gridKey"> 
    <Grid Grid.Row="0" Grid.Column="0" > 
     <Grid.RowDefinitions> 
       .... 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
       .... 
     </Grid.ColumnDefinitions> 
    </Grid> 
</ItemsPanelTemplate> 

そして、それは大丈夫だ、それが動作します。しかし、このGridでは、私は持っていたいと思います、TextBlockと言うでしょう。

<ItemsPanelTemplate x:Key="gridKey"> 
    <Grid Grid.Row="0" Grid.Column="0" > 
     <Grid.RowDefinitions> 
       .... 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
       .... 
     </Grid.ColumnDefinitions> 
     <TextBlock Grid.Row="0" Grid.Column="0" 
        Text="{Binding SomeTextFromVM}"/> 
    </Grid> 
</ItemsPanelTemplate> 

これを実行すると、すべてが損なわれます。私はそれをどのように修正すべきですか?

答えて

0

通常、ItemsPanelテンプレートに加えてItemsControlのTemplateに要素を追加します。

ただし、ItemsPanel(ItemsPresenterで管理されている)のGridにこれらの要素を追加することはできません。

<ItemsControl ...> 
    <ItemsControl.Template> 
     <ControlTemplate TargetType="ItemsControl"> 
      <Grid> 
       ... 
       <ItemsPresenter/> 
       <TextBlock Grid.Row="0" Grid.Column="0" 
          Text="{Binding SomeTextFromVM}"/> 
      </Grid> 
     </ControlTemplate> 
    </ItemsControl.Template> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Grid> 
       ... 
      </Grid> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     ... 
    </ItemsControl.ItemTemplate> 
    <ItemsControl.ItemContainerStyle> 
     ... 
    </ItemsControl.ItemContainerStyle> 
</ItemsControl> 
+0

これは何ですか? –

+0

あなたのアイテムがテンプレートに追加される場所です。グリッド内に何かが必要な場合は、

+0

の質問を更新する前または後に追加してください。このようにしてスタイルが乱されます。私の目標は、ボードゲームのように、グリッドの端にボタンを置くことです。 –

関連する問題