2

オブジェクトの配列をリストアップして、アイテムを水平方向に均等に広げたいと思います。データバインドされた配列でない場合は、適切な数の列を持つグリッドを作成し、各項目を列に割り当てます。問題は、データバインドされたリストコントロールでそれを行う方法がわからないことです。

安価な代替手段として、次のようなItemsControlのItemsPanelとしてスタックパネルを使用してアイテムを水平方向にリストします。

    <ItemsControl ItemsSource="{Binding Path=ValveSettings}" Grid.Row="0">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Label Content="{Binding Path=Name}" Grid.Row="0" />
                    <ScrollBar Orientation="Vertical" Grid.Column="0" Grid.Row="1" Minimum="0" Maximum="100000" Value="{Binding Path=DelayInMicroseconds}" SmallChange="100" LargeChange="1000" />
                    <TextBox Text="{Binding Path=DelayInMicroseconds}" Grid.Row="2" />
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

それらを均等に広げる方法はありますか?

4

2 に答える 2

3

これは、素晴らしく機能する CodeWarrior のコメントの結果です。

    <ItemsControl ItemsSource="{Binding Path=Settings.Valves}" Grid.Row="0">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="1" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Path=Name}" Grid.Row="0" TextAlignment="Center" />
                    <ScrollBar Orientation="Vertical" Grid.Column="0" Grid.Row="1" Minimum="0" Maximum="100000" Value="{Binding Path=DelayInMicroseconds}" SmallChange="100" LargeChange="1000" />
                    <TextBox Text="{Binding Path=DelayInMicroseconds}" Grid.Row="2" TextAlignment="Center" />
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
于 2012-04-04T20:41:57.013 に答える
0

私は通常、ItemTemplate のマージンを使用してリスト アイテムを分割します。余白を開始しない側に置きます (つまり、リストが左から入力される場合は、右に余白を置きます)。このように、連続する各アイテムは、前のアイテムから x ピクセルで配置されます。

上記の例では、Grid 要素にマージンを追加しました。

        <DataTemplate>
            <Grid Margin="0 0 8 0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Label Content="{Binding Path=Name}" Grid.Row="0" />
                <ScrollBar Orientation="Vertical" Grid.Column="0" Grid.Row="1" Minimum="0" Maximum="100000" Value="{Binding Path=DelayInMicroseconds}" SmallChange="100" LargeChange="1000" />
                <TextBox Text="{Binding Path=DelayInMicroseconds}" Grid.Row="2" />
            </Grid>
        </DataTemplate>
于 2012-04-04T15:54:36.097 に答える