WPF Linq to Sql Binding Update

B

Bill McCormick

I have a TextBlock with the Text property set to do a Binding like so:

Text="{Binding CurrentTare}"

The DataContext is set in the Parent StackPanel container from the following:

SomeStackPanel.DataContext = _db.Trks.OrderBy(t => t.TrkId);

and Trks is defined as:

public System.Data.Linq.Table<Trk> Trks


and the CurrentTare property is as follows:

public partial class Trk : INotifyPropertyChanging, INotifyPropertyChanged
{
public double CurrentTare {
get {
var ctare = (from t in TTares
where (t.TTareDateTime) == (from r in TTares
select r.TTareDateTime).Max()
select t.TTareWeight).Single<double>();
return ctare;
}
}
}


I've tried several things with no success including:

_db.Refresh(RefreshMode.OverwriteCurrentValues, _db.TTares);
_db.Refresh(RefreshMode.OverwriteCurrentValues, _db.Trks);

trk.UpdateTare();

BindingExpression binding =
txtCurrentTare.GetBindingExpression(TextBlock.TextProperty);
binding.UpdateTarget();
binding.UpdateSource();

where trk.UpdateTare() is also from the Trk class:

public partial class Trk : INotifyPropertyChanging, INotifyPropertyChanged
{
public void UpdateTare() {
this.SendPropertyChanging();
this.TTares.Load();
this.SendPropertyChanged("TTares");
this.SendPropertyChanged("CurrentTare");
}
}


Ideas????


TIA, Bill
 
B

Bill McCormick

I have a TextBlock with the Text property set to do a Binding like so:

Text="{Binding CurrentTare}"

The DataContext is set in the Parent StackPanel container from the
following:

SomeStackPanel.DataContext = _db.Trks.OrderBy(t => t.TrkId);

and Trks is defined as:

public System.Data.Linq.Table<Trk> Trks


and the CurrentTare property is as follows:

public partial class Trk : INotifyPropertyChanging, INotifyPropertyChanged
{
public double CurrentTare {
get {
var ctare = (from t in TTares
where (t.TTareDateTime) == (from r in TTares
select r.TTareDateTime).Max()
select t.TTareWeight).Single<double>();
return ctare;
}
}
}


I've tried several things with no success including:

_db.Refresh(RefreshMode.OverwriteCurrentValues, _db.TTares);
_db.Refresh(RefreshMode.OverwriteCurrentValues, _db.Trks);

trk.UpdateTare();

BindingExpression binding =
txtCurrentTare.GetBindingExpression(TextBlock.TextProperty);
binding.UpdateTarget();
binding.UpdateSource();

where trk.UpdateTare() is also from the Trk class:

public partial class Trk : INotifyPropertyChanging, INotifyPropertyChanged
{
public void UpdateTare() {
this.SendPropertyChanging();
this.TTares.Load();
this.SendPropertyChanged("TTares");
this.SendPropertyChanged("CurrentTare");
}
}

Got it working!!!

Went back to using trk.TTares.Add(tare) (some it does work after all!) and
then made the following changes:

public partial class Trk : INotifyPropertyChanging, INotifyPropertyChanged
{
public void UpdateTare() {
this.SendPropertyChanging();
this.SendPropertyChanged("CurrentTare");
}

public double CurrentTare {
get {
var ctare = (from t in TTares
orderby t.TTareDateTime descending
select t.TTareWeight).First();

return ctare;
}
}
}
 
Top