views:

729

answers:

0

I am using an ItemsControl bound to a CollectionViewSource. I set its ItemsPanel to a WrapPanel (with orientation initially set to horizontal) and am using a button to toggle between horizontal and vertical orientation. Basically changing the ItemsPanel to point at different resources, inside the button click handler. This works fine.

I am currently trying to take advantage of the CollectionViewSource's grouping abilities to create groups of items. I created a GroupDescription and added it to the CollectionViewSource's GroupDescriptions. I then added a GroupStyle to my ItemsControl and removed the orignal

ItemsPanel={StaticResource HorizontalPanel}.

The new code is shown below. Now instead of changing the ItemsPanel in the button click handler I want to change the GroupStyle's Panel. But this doesnt work...Any ideas?

Click Handler initially had

Display.ItemsPanel = this.Resources["VerticalPanel"] as ItemsPanelTemplate;

changed to:

DisplayStyle.Panel = this.Resources["VerticalPanel"] as ItemsPanelTemplate; Also tried Display.GroupStyle[0].Panel = this.Resources["VerticalPanel"] as ItemsPanelTemplate; Both dont work. What am I doing wrong here? Thanks

<ItemsControl Name="Display" ItemTemplateSelector="{StaticResource SomeSelector}">
    <ItemsControl.GroupStyle>
        <GroupStyle x:Name="DisplayStyle" HeaderTemplate="{StaticResource GroupHeader}" Panel="{StaticResource HorizontalPanel}" />
    </ItemsControl.GroupStyle>
    <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
            <Border>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <ItemsPresenter/>
                </ScrollViewer>
            </Border>
        </ControlTemplate>
    </ItemsControl.Template>
</ItemsControl>