WPF databinding

ok, so I never got the databinding to work quite right between my listbox and the various add,update,delete operations I was doing with Linq to SQL.

However, I did get it all to look good, with the listbox getting updated, and this is how I did it.

The magic function was: GetNewBindingList called from my linq table object.

Somehow it feels like the linq to sql class should inform the listbox that it needs to refresh and there should be some magic setting, but for the time being:
XAML extract:

set the datasource in the window:
<Window x:Class="HomerV3_Queries.Window_Queries"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
bind to it at the listbox. "Queries" is the table I'm binding to.:
ItemsSource="{Binding Path=Queries,UpdateSourceTrigger=PropertyChanged}"

C# code called after every database change – note the commented out stuff that does not work:

void PageRefresh()
{
//_context.SubmitChanges();

//_context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, _context.Queries);
//lbQueries.UpdateLayout();
//lbQueries.ItemsSource = null;
//lbQueries.Items.Clear();
lbQueries.ItemsSource = _context.Queries.GetNewBindingList();
//lbQueries.Refresh();
lbQueries.SelectedIndex = -1;
txtQuery.Text = "";
txtTitle.Text = "";
}

Advertisement

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.