3

この XAML があり、実行時に WrapGrid オブジェクトの属性である MaximumRowsOrColumns 属性の値を変更する方法を知りたいです。

<ScrollViewer x:Name="LayoutRoot" IsTabStop="True">
    <ItemsControl Name="m_pageContainer" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Center" VerticalAlignment="Center">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Pink" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="YellowGreen" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Blue" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Red" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Yellow" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Green" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="Gray" />
        <Rectangle Margin="10,10,10,10" Height="50" Width="40" Fill="LightBlue" />
    </ItemsControl>
</ScrollViewer>

私は C# または C++/CX でこれを行う方法を無駄に探してきました。

ありがとう

ロジャー

4

1 に答える 1

2
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="{Binding MaxRowsOrColumns}"/>

これは、datacontext で呼び出されるプロパティがあることを前提としていMaxRowsOrColumnsます (これを追加する必要があります)。次に、プロパティの値を変更するだけです。

于 2012-09-19T18:07:59.710 に答える