WinRT XAML binds to the context of the parent data in the DataTemplate

I am trying to figure out how to associate a combo box with the parent data content from ComponentOne FlexGrid. I saw Tyler's question and tried this, but when I started the WinRT application, the combo box is empty. I managed to get it working by setting my ViewModel as a static resource on the page, but I don't understand if there are any negative consequences for this, instead of setting 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>
+4
source share

Source: https://habr.com/ru/post/1584147/


All Articles