In Depth: Data Binding with Intersoft Presenter for Silverlight – Part2
Hi all,
In the previous post we discuss about the various factor that you can do with data binding with intersoft presenter. Now i want to discuss about how to add additional query / custom query and how to change the data source of intersoft presenter at run time.
Using custom query
Often in developing an application we perform more complex query rather just selecting all the data and display it, and how can we achieve that using Intersoft Presenter and Intersoft Data Source?
As mentioned before there are two types of data binding in Intersoft Presenter:
- Bound to Intersoft Data Source control.
- Unbound to Intersoft Data Source control.
In unbound to Intersoft Data Source control, the developer only need to specify the ItemSource with the processed data source, so developer is responsible to give the ItemsSource with the correct data.
In bound to Intersoft Data Source control, the developer can interrupt the selecting process using Intersoft Data Source’s Selecting event handler and provide the custom query there.
Add the custom query at code behind.
Note that you might want to keep some of the sort / filter / paging expression from the actual data source select arguments. The above code shows you how to initialize the query and then put the custom / additional filter after it.
In this case i’m adding additional filter (Discontinued == false) so that it will shows Products data with page size of 20 and filter-out the discontinued products.
Changing Data Source at runtime
We also often developing an application where it requires us to change the data source of our presenter, you can do that by changing the data member of your presenter (for Bound to Intersoft Data Source control scenario) and call RefreshData(true) method, or you can specify the new ItemsSource using RefreshData(newItemSource, true) for Unbound to Intersoft Data Source control scenario.
During combox box items selection changed:
Results:
If you want to see the sample code, you can download it from here.
Regards
Andry
to run the specific samples in this post, change the following code in app.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
// In Depth Data Binding – part 2
// this.RootVisual = new InDepth_DataBinding2_CustomQuery();
// this.RootVisual = new InDepth_DataBinding2_ChangeDataSource();
}
open one of the commented code.
ansoesil
July 22, 2009 at 9:09 pm