Using RIA Services FilterDescriptor from code behind
I was wondering if it's possible to use the FilterDescriptor control from code behind?
On the page load of my form I set the datasource of a grid in the code behind, not using a Domain开发者_Python百科DataSource control, like:
TestDomainContext context = new TestDomainContext();
dataGridEmployees.ItemsSource = context.EmployeePositions;
context.Load(context.GetEmployeesWithPositionQuery());
I have a textbox on my page that the user can enter into to filter on employee position.
Is it now possible to add FilterDescriptor to the source of the DataGrid in code behind? Or would I manually need to filter the results of the context.GetEmployeesWithPositionQuery, for example on KeyUp event of the filter TextBox?
It worked for me as follows.
You can add a DomainDataSource but control it from code behind instead of declarative in xaml:
DomainDataSource testDDS.DomainContext = context;
testDDS.QueryName = "GetEmployeesWithPositionQuery";
testDDS.Load;
Then, as I read in Set FilterDescriptor in code - C# Silverlight 4 WCF, you can create a FilterDescriptor in code behind and add it to your DDS:
FilterDescriptor testFilter = new FilterDescriptor() { PropertyPath = "Name",
Operator = FilterOperator.Contains };
Binding nameBinding = new Binding("Text") { ElementName = "txtFilterName" };
BindingOperations.SetBinding(testFilter, FilterDescriptor.ValueProperty, nameBinding);
testDDS.FilterDescriptors.Add(testFilter);
Hope this helps,
flip
精彩评论