0

動的に作成されたデータ テンプレート アイテム (オブジェクトにバインド) を表形式で表示しようとしています。スタック パネルとラップ パネルの両方が、最初にボタンを使用したときのようにフォーマットされません。私のパネル コントロールは、実際にはその中にある項目をフォーマットしていないと信じるようになりました。

ここに私のコードのいくつかの関連サンプルがあります:

メイン ウィンドウの背後にあるコード C#

int numTapeSlots = 16;
public ObservableCollection<Tape> topTapes;

    public MainWindow()
    {
        InitializeComponent();
        topTapes = new ObservableCollection<Tape>();           
        topTapeSlots.ItemsSource = topTapes;            

        //Create Buttons Top Tray
        for (int i = 1; i <= (numTapeSlots / 2); i++)
        {
            topTapes.Add(new Tape(i));
        }
     }

xaml

<Window.Resources>
  <DataTemplate x:Key="TapeSlot">
    <Border  MouseUp="Border_MouseUp"
             BorderBrush="Black"
             BorderThickness="5">
      <Grid>
        <TextBlock x:Name="slotLocation"
                   Text="{Binding Path=tapeLocation}"
                   Height="25"
                   Width="30" />

      </Grid>
    </Border>
  </DataTemplate>
</Window.Resources>

<WrapPanel x:Name="wpTopTray"
           Grid.Column="1"
           Margin="20,20,20,20"
           VerticalAlignment="Top">
  <ItemsControl Name="topTapeSlots"
                ItemTemplate="{StaticResource TapeSlot}" />
</WrapPanel>

注: WrapPanel はボタンで正常に動作しました

これで、オブジェクトが垂直に一列に表示されます。wrapPanel コントロールのプロパティをほとんど無視しています。

4

1 に答える 1

1

あなたがすべきことは、ItemsPanel を使用することです。

        <ItemsControl Name="topTapeSlots" ItemTemplate="{StaticResource TapeSlot}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
于 2013-06-26T20:37:47.083 に答える