MVVM and Databinding with UniformGrid

Posted by JP on Stack Overflow See other posts from Stack Overflow or by JP
Published on 2010-12-20T21:27:49Z Indexed on 2010/12/21 13:54 UTC
Read the original article Hit count: 193

Filed under:
|
|
|
|

I'm trying to style the back of a WPF chart with some rectangles. I'm using MVVM, and I need the rectangles to be uniformly sized. When defined via Xaml, this works with a fixed "BucketCount" of 4:

<VisualBrush>
  <VisualBrush.Visual>
  <UniformGrid Height="500" Width="500" Rows="1" Columns="{Binding BucketCount}">
    <Rectangle Grid.Row="0" Grid.Column="0" Fill="#22ADD8E6" />
    <Rectangle Grid.Row="0" Grid.Column="1" Fill="#22D3D3D3"/>
    <Rectangle Grid.Row="0" Grid.Column="2" Fill="#22ADD8E6"/>
    <Rectangle Grid.Row="0" Grid.Column="3" Fill="#22D3D3D3"/>
  </UniformGrid>        
 </VisualBrush.Visual>
<VisualBrush>

How can I bind my ObservableCollection of Rectangles? There is no "ItemsSource" property on UniformGrid. Do I need to use an ItemsControl? If so, how can I do this?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about Silverlight