WinRT XAML绑定到DataTemplate中的父数据上下文

时间:2015-04-23 03:25:27

标签: c# xaml winrt-xaml componentone c1flexgrid

我试图找出如何从ComponentOne FlexGrid中将组合框绑定到父数据上下文。我看到了Tyler's question并尝试了这个但是,当我运行我的WinRT应用程序时,组合框是空的。我能够通过将我的ViewModel设置为页面上的静态资源来使其工作,但我不清楚这样做是否有任何负面影响,而不是设置Page.DataContext。任何帮助将不胜感激。

工作示例:

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

并且

        <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>

0 个答案:

没有答案