在运行时更改代码中属性的值

时间:2012-09-19 14:40:01

标签: c# c++ xaml windows-8 windows-runtime

我有这个XAML,在运行时我想知道如何更改MaximumRowsOrColumns属性的值,该属性是WrapGrid对象的属性:

<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中实现此目的的方法。

由于

罗杰

1 个答案:

答案 0 :(得分:2)

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

这假设您在datacontext中有一个名为MaxRowsOrColumns的属性(您应该添加它)。然后你所要做的就是改变你的财产的价值。