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

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实现这个功能的方法。

谢谢

Roger


你尝试将它的值绑定到你的ViewModel或等价物上了吗? - N_A
1个回答

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

假设您的数据上下文中有一个名为MaxRowsOrColumns的属性(您应该添加此属性)。然后,您只需要更改属性的值即可。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接