开发者

Silverlight Template databinding issue

I am using the Telerik framework for creating a RadGridView with child elements in Silverlight 4.

<telerikGrid:RadGridView x:Name="itemsGrid" Grid.Row="1" AutoGenerateColumns="{Binding AutoGenerateColumn, Mode=TwoWay}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemsSource="{Binding Items, Mode=TwoWay}" CanUserInsertRows="True" ShowInsertRow="True" CanUserDeleteRows="True">              
            <telerikGrid:RadGridView.Columns>
                <telerikGrid:GridViewToggleRowDetailsColumn />

                <telerikGrid:GridViewDataColumn Header="Item 1" DataMemberBinding="{Binding Item1}" UniqueName="Item1" />
                <telerikGrid:GridViewComboBoxColumn Header="Group"  UniqueName="Group" 
                                                    ItemsSource="{Binding Groups.Items}" SelectedValueMemberPath="GroupId" DisplayMemberPath="GroupNames"  />
                <telerikGrid:GridViewComboBoxColumn Header="Supplier" UniqueName="Supplier" 
                                                    ItemsSource="{Binding Suppliers}" SelectedValueMemberPath="CompanyS" DisplayMemberPath="CompanyName"  />
                <telerikGrid:GridViewDataColumn Header="Not in use" DataMemberBinding="{Binding inUse}" UniqueName="inUse" />
</telerikGrid:RadGridView.Columns>

            <telerikGrid:RadGridView.ChildTableDefinitions>
                <telerikGrid:GridViewTableDefinition />
            </telerikGrid:RadGridView.ChildTableDefinitions>

            <telerikGrid:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <StackPanel>
                        <telerikGrid:RadGridView x:Name="childGrild" Grid.Row="1" AutoGenerateColumns="False" ItemsSource="{Binding ChildList}" CanUserInsertRows="True" CanUserDeleteRows="True" IsReadOnly="False" ShowInsertRow="True" ShowGroupPanel="False">
                            <telerikGrid:RadGridView.Columns>
                                                <telerikGrid:GridViewDataColumn Header="Part S" DataMemberBinding="{Binding PartS}" UniqueName="PartS" />

                                <telerikGrid:GridViewComboBoxColumn Header="Tools" ItemsSource="{Binding ElementName=control, Path=DataContext.Tools}" DataMemberBinding="{Binding PartS}" SelectedValueMemberPath="Id" DisplayMemberPath="Name" />


                            </telerikGrid:RadGridView.Columns>

                        </telerikGrid:RadGridView>

                    </StackPanel>
                </DataTemplate>
            </telerikGrid:RadGridView.HierarchyChildTemplat开发者_StackOverflowe>

        </telerikGrid:RadGridView>

As you can see, each row in the grid has a child GridView, the problem is however that i cant get the Combobx in the gridview to display any data, its always empty. If i move it outside the child tempate it works fine, and the Items which are in the Tools list is shown. To access the list, which is a property of the controls datacontext, i gave the control a Name (control), and used Path=DataContex.Tools, which i read should work.

Anyone has any idea why the ComboBox is not populated with data? I have checked that all the propertie names are correct, and that there actually are data there to show.


RadGridView and ElementName don't mix very well. In your case, the 'control' element can't be found. You could use a DataContextProxy as shown in the link. It solved an issue I had that was similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜