<UserControl x:Class="Hierarchy_RIA.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
             xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" 
             xmlns:my="clr-namespace:Hierarchy_RIA.Web" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition  />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:Order, CreateList=true}" 
                                      Height="0" 
                                      LoadedData="orderDomainDataSource_LoadedData" 
                                      Name="orderDomainDataSource" QueryName="GetOrdersQuery" Width="0">
            <riaControls:DomainDataSource.DomainContext>
                <my:NWDomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>
        <telerik:RadGridView ItemsSource="{Binding ElementName=orderDomainDataSource, Path=Data}"
                             AutoGenerateColumns="False"
                             Sorting="orderRadGridView_Sorting"
                             Name="orderRadGridView" >
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding OrderID}" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding ShipCity}" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding OrderDate}" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding MaxUnitPrice}" Header="Max Unit Price" />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition />
            </telerik:RadGridView.ChildTableDefinitions>
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView ItemsSource="{Binding Order_Details}" ShowGroupPanel="False" />
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>
        <riaControls:DomainDataSource AutoLoad="False" d:DesignData="{d:DesignInstance my:Employee, CreateList=true}" Height="0" LoadedData="employeeDomainDataSource_LoadedData" Name="employeeDomainDataSource" QueryName="GetEmployeesQuery" Width="0">
            <riaControls:DomainDataSource.DomainContext>
                <my:EmployeeDomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

        <telerik:RadGridView Grid.Row="1" 
                             AutoGenerateColumns="False"
                             RowLoaded="RadGridView_RowLoaded"
                             ItemsSource="{Binding ElementName=employeeDomainDataSource, Path=Data}" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding EmployeeID}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName}" />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition>
                    <telerik:GridViewTableDefinition.Relation>
                        <telerik:TableRelation IsSelfReference="True">
                            <telerik:TableRelation.FieldNames>
                                <telerik:FieldDescriptorNamePair ParentFieldDescriptorName="EmployeeID" ChildFieldDescriptorName="ReportsTo">                                    
                                </telerik:FieldDescriptorNamePair>
                            </telerik:TableRelation.FieldNames>
                        </telerik:TableRelation>
                    </telerik:GridViewTableDefinition.Relation>
                </telerik:GridViewTableDefinition>
            </telerik:RadGridView.ChildTableDefinitions>
        </telerik:RadGridView>
        <StackPanel>
            <Button Content="Open child" Click="Button_Click"/>
        </StackPanel>
    </Grid>
</UserControl>
