0
Grid
をPanelTemplate
とする必要があります。それは大きな問題ではないが、私はその他のコントロールを持っている必要がある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>
これを実行すると、すべてが損なわれます。私はそれをどのように修正すべきですか?
あなたのアイテムがテンプレートに追加される場所です。グリッド内に何かが必要な場合は、 –
の質問を更新する前または後に追加してください。このようにしてスタイルが乱されます。私の目標は、ボードゲームのように、グリッドの端にボタンを置くことです。 –