2
votes

I have a DataGrid. The ItemsSource of this DataGrid is set in the Completed event of a WCF call.However, when adding a Detail Datagrid inside the master grids DataTemplate and naming it appropriately... Ineed to fill it master grids selection change event but my codebehind does not recognise the detail grid. I cant set the ItemsSource of grdDetail like I do with grdMaster.So how i can fill my detail datagrid ?

Xaml File

  <Grid x:Name="LayoutRoot">

    <sdk:DataGrid x:Name="dgCustList" AutoGenerateColumns="False" Background="Transparent" SelectionChanged="dgCustList_SelectionChanged">
        <sdk:DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <StackPanel x:Name="stkPanel">
                    <sdk:DataGrid x:Name="dgCustDetail" RowDetailsVisibilityMode="VisibleWhenSelected" AutoGenerateColumns="False"  Background="Transparent"/>
                </StackPanel>
            </DataTemplate>
        </sdk:DataGrid.RowDetailsTemplate>
    </sdk:DataGrid>
    <Grid.Projection>
        <PlaneProjection x:Name="Projection"/>
    </Grid.Projection>
</Grid>

And CodeBehind

  public MusteriListe()
    {
        InitializeComponent();
        var stb1 = new Storyboard { Duration = new Duration(TimeSpan.FromSeconds(1)), SpeedRatio = 3 };

        var daY1 = new DoubleAnimation { From = 0.00, To = 90.00 };
        Storyboard.SetTargetName(daY1, "Projection");
        Storyboard.SetTargetProperty(daY1, new PropertyPath("RotationX"));
        stb1.Children.Add(daY1);
        this.Resources.Add("EndOfPage", stb1);

        var stb = new Storyboard();
        stb.Duration = new Duration(TimeSpan.FromSeconds(1));
        stb.SpeedRatio = 3;

        var daY = new DoubleAnimation { From = -90.00, To = 0.00 };
        Storyboard.SetTargetName(daY, "Projection");
        Storyboard.SetTargetProperty(daY, new PropertyPath("RotationX"));
        stb.Children.Add(daY);
        Resources.Add("StartOfPage", stb);

        dgCustList.Columns.Add(new DataGridTextColumn
        {
            Header = "ID",
            Binding = new Binding("CustomerID")
        });
        dgCustList.Columns.Add(new DataGridTextColumn
        {
            Header = "Müşteri Ad",
            Binding = new Binding("CustomerName")
        });
        dgCustList.Columns.Add(new DataGridTextColumn
        {
            Header = "Müşteri Soyad",
            Binding = new Binding("CustomerSurname")
        });
        dgCustList.Columns.Add(new DataGridTextColumn
        {
            Header = "Müşteri Tel",
            Binding = new Binding("CustomerPhone")
        });
        LoadGrid();
    }
    private void LoadGrid()
    {
        var client = new EczServiceClient();
        client.CustomerInfoCompleted += client_CustomerInfoCompleted;
        client.CustomerInfoAsync();
    }
    void client_CustomerInfoCompleted(object sender, CustomerInfoCompletedEventArgs e)
    {
        dgCustList.ItemsSource = e.Result;
    }

    private void dgCustList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

        var customer = dgCustList.SelectedItem as CustomerInfo;
        if (customer == null) return;
        var client = new EczServiceClient();
        client.CustomerDetailCompleted += client_CustomerDetailCompleted;
        client.CustomerDetailAsync(customer.CustomerID);

    }
    void client_CustomerDetailCompleted(object sender, CustomerDetailCompletedEventArgs e)
    {
        IN HERE I WANT TO FILL DATAGRID LIKE MASTER GRID BUT ITS NOT LET ME ( dgCustDetail.ItemSource = e.Result)
    }
1

1 Answers

0
votes

You did NOTdefine binding for you detail data grid and you set the autogenerate columns to false. You need to define the binding either in XAML or in code behind before the client_CustomerDetailCompleted event fires. Simply setting the item source alone won't work because the detail datagrid does not contain columns. This is where MVVM pattern comes in handy.