I’m a newbie to Visual Studio (2010) and Expression Studio (4).
I have been trying to get a TreeView to connect to a .mdb database that I have connected in Visual Studio (using Silverlight Business Application) to show a Navigation Tree for the Name Properties in each table. I have 2 levels of hierarchy:
(there are many more properties than shown but these are the only required)
- Root Level: Location Table [LocationName Property]
- First Level: Area Table [AreaName Property] [LocationID]
- Second Level: Inspection Table [InspectionName Property] [AreaID]
I have tried many ways to connect and none seem to work – I am quite happy now with making a TreeView template with a connection to hierarchical Sample Data created in Expression Blend. Unfortunately, I can only seem to make a connection with the top level of my real database – so it only shows the names of the locations and won’t expand any further.
I have no idea what to do. The code I’m using is: (no code-behind)
Home.xaml
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Location, CreateList=true}" Height="0" LoadedData="locationDomainDataSource_LoadedData_1" Name="locationDomainDataSource" QueryName="GetLocationsQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:InspectDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<sdk:TreeView Height="200" ItemsSource="{Binding ElementName=locationDomainDataSource, Path=Data}" Name="locationTreeView1" Width="200" >
<sdk:TreeView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="NavigationTreeResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</sdk:TreeView.Resources>
<sdk:TreeView.ItemTemplate>
<StaticResource ResourceKey="RootLevel"/>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
Navigation Tree Resource Dictionary
<common:HierarchicalDataTemplate x:Key="Level2">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,3,0"
FontStyle="Italic"
Text="{Binding Path=Name}" />
</StackPanel>
</common:HierarchicalDataTemplate>
<common:HierarchicalDataTemplate x:Key="Level1"
ItemsSource="{Binding Path=Inspections}"
ItemTemplate="{StaticResource Level2}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,3,0"
Text="{Binding Path=Name}" />
</StackPanel>
</common:HierarchicalDataTemplate>
<common:HierarchicalDataTemplate x:Key="RootLevel"
ItemsSource="{Binding Path=Areas}"
ItemTemplate="{StaticResource Level1}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,3,0"
Text="{Binding Path=Name}"
FontWeight="Bold" FontSize="12" />
</StackPanel>
</common:HierarchicalDataTemplate>
Domain Service (c#) GetLocationsQuery
public IQueryable<Location> GetLocations()
{
return this.ObjectContext.Locations.OrderBy(l=>l.Name);
}
Is it perhaps something to do with the Query used? Should I be putting the information I need for the treeview in the GetLocationsQuery?
- If so how do I put in the query to return a list of location names, child area names and child inspection names?
Thank you in advance.
Have found a solution, I will post for others in the case it is needed:
It was the domain service and metadata info that needed to be changed =>
In the metadata file, each EntityCollection in a table that you want the service to pass back needs [Include] e.g.:
Locations Table
Areas Table
Inspections Table
and in the domain service file the query used requires:
where each “.Entity” is the name of the collection entities that have been included in the metadata file.
Back to the xaml – it should work with the code as long as the Binding path names are the same as the EntityCollection Names.
🙂 Hope that has been useful