1

以下に示すように、行数と列数の両方が動的なレイアウトを作成しようとしています。

画像

すべてのコントロールを 1 つのグリッドでホストして、上から下、左から右にタブ操作できるようにしたいと考えています。私が動作させようとしているコードを以下に示します。

<Grid base:GridHelpers.RowCount="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dx:DXWindow}, Path=Groups.Count}" Name="EnclosingGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="180" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <!--Labels-->
    <ItemsControl ItemsSource="{Binding Rows}" ItemsPanel="{Binding ElementName=EnclosingGrid}">
        <ItemsControl.ItemContainerStyle>
            <Style>
                <Setter Property="Grid.Row" Value="{Binding RowIndex}" />
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Label Grid.Column="0" Content="{Binding Path=FieldName}" VerticalContentAlignment="Center" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    <!--Process fields-->
    <ItemsControl ItemsSource="{Binding Cells}" ItemsPanel="{Binding ElementName=EnclosingGrid}">
        <ItemsControl.ItemContainerStyle>
            <Style>
                <Setter Property="Grid.Row" Value="{Binding ParentRow.RowIndex}" />
                <Setter Property="Grid.Column" Value="{Binding ColumnIndex}" />
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBox />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

囲んでいるグリッドに属性を設定しようとしましItemsPanelたが、残念ながらうまくいきません。

ItemsPanelTemplateグリッドを内部として設定する唯一の方法はありItemsControlますか?

他のアプローチはありますか?または、自分でロールバックする必要がありItemsControlますか?

4

1 に答える 1

0

ItemsPanelプロパティ タイプはItemsPanelTemplateであるため、このプロパティを既存のコントロールに直接バインドすることはできません。

このプロパティは、アイテムのコンテナー コントロールを提供することになっている一種のファクトリ クラスと考えることができます。これは、MSDNがこの型について文字通り言っていることです: ItemsPresenter が ItemsControlの項目のレイアウトのために作成するパネルを指定します。

于 2013-02-20T14:50:07.137 に答える