3
votes

I am using grouped GridView in a windows 8 metro application, I have a VariableSizedWrapGrid in ItemsPanelTemplate , and want to bind the MaximumRowsOrColumns Property, but it is not binding correctly.

Here is my XAML

<GridView  ItemsSource="{Binding Source={StaticResource groupeddata}}" >
    <GridView.ItemTemplate>
        <DataTemplate>
            <Grid Width="120" Height="150" >
                <!--some controls here binded correctly.-->
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid Margin="1,0,0,6">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding maxGridCoulmns}"></TextBlock>
                            <!--work ok here -->
                            <TextBlock   Foreground="Black" Padding="0,0,0,20" Text="{Binding headerText}"  />
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
            <GroupStyle.Panel >
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid    Orientation="Horizontal"  MaximumRowsOrColumns="{Binding maxGridCoulmns}"  Margin="0,0,80,0"/>
                    <!--not binding  here -->                         
                </ItemsPanelTemplate>
            </GroupStyle.Panel>
        </GroupStyle>
    </GridView.GroupStyle>
</GridView>
1
Please, format your XAML properly. If you want people to take their time helping you, at least show that you put in some effort yourself. - eandersson
Visual Studio's Output window gives some details when a Binding fails. What does it say? - HDW Production
It shows this message: "Error: BindingExpression path error: 'maxGridCoulmns' property not found on 'Windows.UI.Xaml.DependencyObject'. BindingExpression: Path='maxGridCoulmns' DataItem='Windows.UI.Xaml.DependencyObject'; target element is 'Windows.UI.Xaml.Controls.VariableSizedWrapGrid' (Name='null'); target property is 'MaximumRowsOrColumns' (type 'Int32')" - Ishti
I have never come across PropertyName in pascal case - Tilak

1 Answers

6
votes

You have to cast the DependencyProperty to ICollectionViewGroup to get the actual group object.

In code that would be var actualGroup = (group as Windows.UI.Xaml.Data.ICollectionViewGroup).Group; - in XAML all you have to do is add the prefix Group. to the binding path.

So in your XAML, just edit the binding like this:

<ItemsPanelTemplate>
    <VariableSizedWrapGrid
        Orientation="Horizontal"
        MaximumRowsOrColumns="{Binding Group.maxGridCoulmns}"
        Margin="0,0,80,0"/>
</ItemsPanelTemplate>