Mike
Mike

Reputation: 1738

WinRT XAML Bind to Parent Data Context in DataTemplate

I am trying to figure out how to bind a a combo box to a parent data context from within a ComponentOne FlexGrid. I saw Tyler's question and tried this but, when I run my WinRT app, the combo box is empty. I was able to get it working by setting my ViewModel as a static resource on the page, but I am unclear if there are any negative implications to doing this instead of setting the Page.DataContext. Any help would be appreciated.

Working Example:

                <ResourceDictionary>
                <DataTemplate x:Key="Permission">
                    <CheckBox HorizontalAlignment="Center" 
                        IsChecked="{Binding IsChecked, Mode=TwoWay}"/>
                </DataTemplate>
                <vm:PermissionDetailsViewModel x:Key="ViewModel" />
            </ResourceDictionary>

And

        <c1:C1FlexGrid Margin="35 10" 
                   Grid.Row="2" 
                   GroupRowPosition="AboveData"
                   Name="C1FlexGrid"
                   ItemsSource="{Binding PermissionsCollectionView}"
                   BorderThickness="1"
                   AutoGenerateColumns="False">

        <c1:C1FlexGrid.Columns >
            <c1:Column Binding="{Binding Name}" Header="Permission Name" Width="3*"></c1:Column>
            <c1:Column CellTemplate="{StaticResource Permission}" Header="User Has Permission" Width="1*" />
            <c1:Column Width="1*">
                <c1:Column.CellTemplate>
                    <DataTemplate>
                        <!-- Where I Bind to the Parent (ViewModel) Data Context -->
                        <ComboBox ItemsSource="{Binding Path=Scopes, Mode=TwoWay, Source={StaticResource ViewModel}}"
                                  Style="{StaticResource ComboBox}"/>
                    </DataTemplate>
                </c1:Column.CellTemplate>
            </c1:Column>
            <c1:Column></c1:Column>
        </c1:C1FlexGrid.Columns>

    </c1:C1FlexGrid>

Upvotes: 4

Views: 477

Answers (0)

Related Questions