【问题标题】:Changing the value of an attribute in code at runtime在运行时更改代码中属性的值
【发布时间】:2012-09-19 14:40:00
【问题描述】:

我有这个 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 中执行此操作的方法,但徒劳无功。

谢谢

罗杰

【问题讨论】:

  • 您是否尝试过将其值绑定到您的 ViewModel 或您的等价物中?

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


【解决方案1】:
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="{Binding MaxRowsOrColumns}"/>

这假设您的数据上下文中有一个名为MaxRowsOrColumns 的属性(您应该添加它)。那么你所要做的就是改变你的财产的价值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    相关资源
    最近更新 更多