WPF: Change the style of a ViewBox depending upon the amount of data

Posted by Brett Rigby on Stack Overflow See other posts from Stack Overflow or by Brett Rigby
Published on 2010-05-03T10:37:57Z Indexed on 2010/05/03 11:08 UTC
Read the original article Hit count: 478

Filed under:
|
|
|

Hi there,

I have a WPF app that has a ViewBox to display the items in my collection, diplaying a 2-column grid for my results.

What I'd like to do is, depending on the number of items in my collection, change the number of columns. E.g if there are < 10 items in the list, then show them in just 1 column; If there are 10 items in my list, then show them in 2 columns; If there are 20 items in my list, then show 3 columns.

Here's what I have at present:

<Viewbox>
   <ItemsControl ItemsSource="{Binding myCollection}" Style="{DynamicResource myStyle}" />
</Viewbox>

Here's what myStyle currently defines:

<Style x:Key="myStyle" TargetType="{x:Type ItemsControl}">
   <Setter Property=ItemsControl.ItemsPanel">
      <Setter.Value>
         <ItemsPanelTemplate>
           <UniformGrid Columns="2" />
         </ItemsPanelTemplate>
      </Setter.Value>
   </Setter>
</Style>

How can I make this code work to the above requirement? Thanks.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about viewbox