Hello All

I have been searching for a concrete example (In VB) of the following problems to no success… I am new to WPF and trying to understand the concepts of Data Binding, Master/Detail, etc… Clear examples that allow me to tinker and reverse engineer the solution is the best way my mind learns therefore I am requesting help with the following problems. PLEASE if you can lend any assistance, I am all ears and if i can provide any other details please let me know, even with everything here, i'm sure i left something out.. Thank You!!


Problems

1) I have a Parent window, (MainWindow.xaml), which contains a button to add a "New Correspondence". When the button is clicked, the New Correspondence, (NewCorrespondence.xaml), window should open. Once Data is entered into the fields, pressing save will add the data to the DataGrid (and Database), or pressing cancel will close the New Correspondence window and not save the data.

2) I have a Parent window, (MainWindow.xaml), which contains a DataGrid. When a record is double clicked in the DataGrid, The Correspondence Details window, (CorrespondenceDetails.xaml), opens and shows the details of the selected Item. If the user changes any data within a field pressing save will update the changes in the DataGrid (and Database) and clicking cancel will cancel any changes and close the window.


Details

1) This biggest thing I need an example of is how to set up the data binding for the above.
2) My database is Access 2010 (.accdb)
3) I'm Using .Net 4.0
4) Included below are the Xaml code and Code-Behinds.


Code


MainWindow.xaml

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SWICorrespondenceTracker" x:Class="MainWindow"
Title="SWI Correspondence Tracker" Height="400" SizeToContent="Width" ResizeMode="NoResize">
<Window.Resources>
<local:SWICentralAdminDBDataSet x:Key="SWICentralAdminDBDataSet"/>
<CollectionViewSource x:Key="OpenFaxesViewSource" Source="{Binding OpenFaxes, Source={StaticResource SWICentralAdminDBDataSet}}"/>
</Window.Resources>
<Grid Margin="3,3,10,3" DataContext="{StaticResource OpenFaxesViewSource}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Background="DarkBlue">
<Label Foreground="White" Padding="10" FontWeight="Bold" FontSize="24" FontFamily="Arial" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" Content="SWI Correspondence Tracker"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Click="Button_Click" HorizontalAlignment="Left" Margin="10,10,3,0" Padding="3" Content="New Correspondence"/>
</StackPanel>
<DataGrid x:Name="OpenFaxesDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="10" RowDetailsVisibilityMode="VisibleWhenSelected" Grid.Row="2" BorderThickness="1" GridLinesVisibility="None" FontSize="14">
<DataGrid.Columns>

<DataGridTextColumn x:Name="FileCaseAsColumn" Binding="{Binding FileCaseAs}" Header="Case Name" IsReadOnly="True" Width="Auto"/>
<DataGridTextColumn x:Name="CorrTypeColumn" Binding="{Binding CorrType}" Header="Type" IsReadOnly="True" Width="SizeToHeader" />
<DataGridTextColumn x:Name="FaxPagesColumn" Binding="{Binding FaxPages}" Header="Pages" IsReadOnly="True" Width="SizeToHeader" />
<DataGridTextColumn x:Name="StatusColumn" Binding="{Binding Status}" Header="Status" IsReadOnly="True" Width="Auto" />
<DataGridTextColumn x:Name="FileAsColumn" Binding="{Binding FileAs}" Header="Assignee" IsReadOnly="True" Width="Auto"/>
<DataGridTextColumn x:Name="DueDateColumn" Binding="{Binding DueDate, StringFormat=d}" Header="Due Date" IsReadOnly="True" Width="Auto" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>


MainWindow.xaml.vb
Class MainWindow
Private Sub Window_Loaded_1(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
Dim SWICentralAdminDBDataSet As SWICorrespondenceTracker.SWICentralAdminDBDataSet = CType(Me.FindResource("SWICentralAdminDBDataSet"), SWICorrespondenceTracker.SWICentralAdminDBDataSet)
'Load data into the table OpenFaxes. You can modify this code as needed.
Dim SWICentralAdminDBDataSetOpenFaxesTableAdapter As SWICorrespondenceTracker.SWICentralAdminDBDataSetTableAdapters.OpenFaxesTableAdapter = New SWICorrespondenceTracker.SWICentralAdminDBDataSetTableAdapters.OpenFaxesTableAdapter()
SWICentralAdminDBDataSetOpenFaxesTableAdapter.Fill(SWICentralAdminDBDataSet.OpenFaxes)
Dim OpenFaxesViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("OpenFaxesViewSource"), System.Windows.Data.CollectionViewSource)
OpenFaxesViewSource.View.MoveCurrentToFirst()
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
'View Correspondence Details
Dim NewCorrespondence As New NewCorrespondence(Me.OpenFaxesDataGrid.SelectedItem)
NewCorrespondence.ShowDialog()
End Sub
Private Sub OpenFaxesDataGrid_MouseDoubleClick1(sender As Object, e As MouseButtonEventArgs) Handles OpenFaxesDataGrid.MouseDoubleClick
'View CorrespondenceDetails
Dim CorrespondenceDetails As New CorrespondenceDetails(Me.OpenFaxesDataGrid.SelectedItem)
CorrespondenceDetails.ShowDialog()
End Sub
End Class


NewCorrespondence.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SWICorrespondenceTracker" x:Class="NewCorrespondence"
Title="NewCorrespondence" Height="300" Width="300">
<Window.Resources>
<local:SWICentralAdminDBDataSet x:Key="SWICentralAdminDBDataSet"/>
<CollectionViewSource x:Key="OpenFaxesViewSource" Source="{Binding OpenFaxes, Source={StaticResource SWICentralAdminDBDataSet}}"/>
</Window.Resources>
<Grid DataContext="{Binding ElementName=MainWindow.OpenFaxesDataGrid, Path=SelectedItem}">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Text="Case Name:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="FileCaseAs" Height="Auto" Width="Auto" Margin="10" Text="{Binding Path=FileCaseAs}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock Text="Type:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="CorrType" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=CorrType}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Text="Pages:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="FaxPages" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=FaxPages}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<TextBlock Text="Status:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<ComboBox x:Name="Status" Height="Auto" Width="Auto" Margin="10" Text="{Binding Path=Status}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0">
<TextBlock Text="Assignee:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="Assignee" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=Assignee}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1">
<TextBlock Text="Due Date:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="DueDate" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=DueDate}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="3" Grid.Column="1">
<Button Width="50" VerticalAlignment="Center" Margin="10">Save</Button>
<Button Width="50" VerticalAlignment="Center" Margin="10">Cancel</Button>
</StackPanel>
</Grid>
</Window>


NewCorrespondence.xaml.vb
Public Class NewCorrespondence
Public Sub New()
InitializeComponent()
End Sub
' Custom constructor to pass Correspondence Details Data
Public Sub New(ByVal data As Object)
Me.New()
' Bind to Correspondence Detail Data.
Me.DataContext = data
End Sub
Private Sub Window_Loaded_1(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
Dim SWICentralAdminDBDataSet As SWICorrespondenceTracker.SWICentralAdminDBDataSet = CType(Me.FindResource("SWICentralAdminDBDataSet"), SWICorrespondenceTracker.SWICentralAdminDBDataSet)
'Load data into the table OpenFaxes. You can modify this code as needed.
Dim SWICentralAdminDBDataSetOpenFaxesTableAdapter As SWICorrespondenceTracker.SWICentralAdminDBDataSetTableAdapters.OpenFaxesTableAdapter = New SWICorrespondenceTracker.SWICentralAdminDBDataSetTableAdapters.OpenFaxesTableAdapter()
SWICentralAdminDBDataSetOpenFaxesTableAdapter.Fill(SWICentralAdminDBDataSet.OpenFaxes)
Dim OpenFaxesViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("OpenFaxesViewSource"), System.Windows.Data.CollectionViewSource)
OpenFaxesViewSource.View.MoveCurrentToFirst()
End Sub
End Class


CorrespondenceDetails.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SWICorrespondenceTracker" x:Class="NewCorrespondence"
Title="NewCorrespondence" Height="300" Width="300">
<Window.Resources>
<local:SWICentralAdminDBDataSet x:Key="SWICentralAdminDBDataSet"/>
<CollectionViewSource x:Key="OpenFaxesViewSource" Source="{Binding OpenFaxes, Source={StaticResource SWICentralAdminDBDataSet}}"/>
</Window.Resources>
<Grid DataContext="{Binding ElementName=MainWindow.OpenFaxesDataGrid, Path=SelectedItem}">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Text="Case Name:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="FileCaseAs" Height="Auto" Width="Auto" Margin="10" Text="{Binding Path=FileCaseAs}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock Text="Type:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="CorrType" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=CorrType}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Text="Pages:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="FaxPages" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=FaxPages}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<TextBlock Text="Status:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<ComboBox x:Name="Status" Height="Auto" Width="Auto" Margin="10" Text="{Binding Path=Status}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0">
<TextBlock Text="Assignee:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="Assignee" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=Assignee}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1">
<TextBlock Text="Due Date:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="DueDate" Height="Auto" Width="Auto" Margin="10" TextWrapping="Wrap" Text="{Binding Path=DueDate}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="3" Grid.Column="1">
<Button Width="50" VerticalAlignment="Center" Margin="10">Save</Button>
<Button Width="50" VerticalAlignment="Center" Margin="10">Cancel</Button>
</StackPanel>
</Grid>
</Window>


CorrespondenceDetails.xaml.vb
Public Class CorrespondenceDetails
Public Sub New()
InitializeComponent()
End Sub
' Custom constructor to pass Correspondence Details Data
Public Sub New(ByVal data As Object)
Me.New()
' Bind to Correspondence Detail Data.
Me.DataContext = data
End Sub
Private Sub CorrespondenceDetails_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
End Sub
End Class