2012-09-19 39 views
3

代碼更改屬性的值,我有這樣的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中執行此操作的方法。

感謝

羅傑

+0

你有沒有試過將它的值綁定到你的ViewModel或你的等價物上? – mydogisbox

回答

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

這裏假設你有一個名爲您的DataContext MaxRowsOrColumns屬性(你應該增加這一點)。那麼你所要做的就是改變你的財產的價值。

+0

謝謝,這工作。 –