Master/ Detail in Silverlight /wo CodeBehind

Master/ Detail in Silverlight /wo CodeBehind

Old forum URL: forums.lhotka.net/forums/t/6379.aspx


Jack posted on Monday, February 09, 2009

I'm trying to plug in some Master/Detail functionality.  I know there are some limitations on data binding updating other properties etc so I don't want to try too hard.

I have the following:

1) Parent.DataCollectionList
2) Parent.CurrentDataCollectionId    - key from selected item DataCollectionList

3) Parent.DataFieldList
4) Parent.CurrentDataFieldList        - ObservableCollection derived from LINQ to select DataFields where Id = CurrentDataCollectionId


I have a grid bound to both lists.  I can do the master/detail by using code behind on the SelectionChanged of the DataCollectionList

private void gridDataCollections_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (gridDataCollections.SelectedItem == null) return;

            // get the dataEntrySession object
            CslaDataProvider dp = this.Resources["DataEntrySessionDataProvider"] as CslaDataProvider;

            // set the currentDataId to the selected dataID
            ((DataEntrySession)(dp.Data)).CurrentDataId = ((DataCollection)this.gridDataCollections.SelectedItem).DataId;

            gridDataFields.ItemsSource = ((DataEntrySession)(dp.Data)).CurrentDataFields;
        }
      
1) Is the last step, replacing the ItemsSource, not redudent?  I thought if I used an ObservableCollection that any changes would ripple up to the UI?

2) Any idea if there a performance hit to doing that vs. the data just changing?  The filter is instantaneous but the rebinding is slower than I expected

3) Can this be done without CodeBehind?  I saw an example that was close where the detail list;s selectedIndex was bound to an object property.  What I was trying to do was bind the CurrentDataCollectionID to the DataCollectionList.SelectedItem.DataId   assuming that the SelectedItem was a DataCollection.

But my basic XAML skills are seriously letting me down.

any ideas?  This obviously isn't a huge requirement since I have it working but it would be nice.

Andreas replied on Friday, February 13, 2009

I am not sure if I understood your problem right but the simplest way to implement master/detail grid views with csla collections and without code behind is like this:

<Window x:Class="WpfMasterDetail.Window1"   

   xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation   

   xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml   

   xmlns:tk=http://schemas.microsoft.com/wpf/2008/toolkit

   xmlns:MyData="clr-namespace:MyData.DataAccess;assembly=MyData.DataAccess"

   xmlns:csla="clr-namespace:Csla.Wpf;assembly=Csla"

   Title="Window1" Height="300" Width="300">

   <Window.Resources>

        <csla:CslaDataProvider x:Key="MasterCollectionProvider"

                                   FactoryMethod="GetAll"

                                   ObjectType="{x:Type MyData:MyMasterCollectionSet}"

                                   IsInitialLoadEnabled="True"

                                   ManageObjectLifetime="True"/>

    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource MasterCollectionProvider}}">

        <StackPanel>

            <tk:DataGrid IsSynchronizedWithCurrentItem="True"

                  ItemsSource="{Binding}"

                  AutoGenerateColumns="True"/>

            <tk:DataGrid IsSynchronizedWithCurrentItem="True"

                  ItemsSource="{Binding Path=CurrentItem.BuchungSet_By_KontoID}"

                  AutoGenerateColumns="True"/>

        </StackPanel>

    </Grid>

</Window>

Regards,

Andreas

PS:

CurrentItem must not be a property of your BO. It is a property of the ICollectionView interface which wpf uses internaly to wrap your data source.

 

Andreas replied on Friday, February 13, 2009

Sorry...please replace "CurrentItem.BuchungSet_By_KontoID" with "CurrentItem.MyDetailsCollectionSet" where MyDetailsCollection must be a property of MyMasterCollectionSet

 

Jack replied on Tuesday, February 17, 2009

Andreas,

Thank you - I will give it a try this week.

Thanks

jack

Copyright (c) Marimer LLC