I have an Incident Report data form which also lists all possible threat types for user to choose for this Incident Report. The threat types are in Threat table which is hierarchical categorized with parent-child relationship.
So I have 3 tables.
The Incident Report table consists of fields: ReportID (primary,unique), Title, Story….
The Threat table consists of fields: ThreatID (primary,unique), ParentThreatID, Name ….
The third table tied the above 2 tables together. I called it the Mapping table. The Mapping table consists of fields: MappingID (primary,unique), ReportID, and ThreatID. The purpose of the Mapping table is to keep track of the threat types assigned to a report.
In my ViewModel, I have the following in the constructor:
Reports = new ObservableCollection<Report>();
var query = _mgr.Reports.Include("Mappings");
query.ExecuteAsync(op => op.Results.ForEach(this.Reports.Add));
I am able to display the Incident Report DataForm and all possible Threat types from the Threat table in a tree view (HierachicalDataTemplate), and I put checkboxes in front of the tree item. My problem is now I need to check the box of the appropriate Threat if the ReportID existed in the Mapping table. Furthermore, if the ReportID for the Threat does not exist in the Mapping table, I need to add a new record to the Mapping table to keep track of it.
I am not sure how to get to the Report’s related entities of the Mapping records, and assigned them to the checkboxes.
<sdk:TreeView x:Name="treeThreats" itemsSource="{Binding Threats,Source={StaticResource vm}}" >
<sdk:TreeView.ItemTemplate>
<winControls:HierarchicalDataTemplate ItemsSource="{Binding ChildThreats}" >
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="chkThreat" IsChecked="{Binding Mappings, Source={StaticResource vm}}" />
<TextBlock Text="{Binding Name, Mode=OneWay}" Margin="5,0" />
</StackPanel>
</winControls:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
Thank you for your help