Hmm, I'm not sure if these are the main problems, but some issues I noticed:
public partial class DefendantView : Page
{
public int MasterId { get; private set; }
public DefendantView(int ID)
{
InitializeComponent();
GetDefendantById(ID);
MasterId = ID;
}
public void GetDefendantById(int ID)
{
using(DataController context = new DataController())
{
DefendantModel defendant = context.GetDefendantById(ID);
grdDefendantDetails.DataContext = defendant;
}
}
private void AddWitness(object sender, RoutedEventArgs e)
{
DefendantModel st = new DefendantModel();
int defId = Convert.ToInt32(st.ID);
this.NavigationService.Navigate(new AddWitnessView(defId));
}
}
You haven't posted the
DefendantModel
class, but I suspect
AddWitness
isn't doing what you think it is. You're creating a new
DefendentModel
object and getting whatever the default ID is for that class. Maybe you were looking for
int defId = Convert.ToInt32(MasterId);
? Hard to tell without the whole picture of what's going on :)