从代码隐藏中使用 RIA 服务 FilterDescriptor

发布于 2024-09-04 17:03:35 字数 477 浏览 2 评论 0原文

我想知道是否可以从后面的代码使用 FilterDescriptor 控件?

在表单的页面加载中,我在后面的代码中设置了网格的数据源,而不是使用 DomainDataSource 控件,例如:

TestDomainContext context = new TestDomainContext();
dataGridEmployees.ItemsSource = context.EmployeePositions;
context.Load(context.GetEmployeesWithPositionQuery());

我的页面上有一个文本框,用户可以输入该文本框来过滤员工职位。

现在是否可以在代码后面将 FilterDescriptor 添加到 DataGrid 的源中?或者我是否需要手动过滤 context.GetEmployeesWithPositionQuery 的结果,例如过滤器 TextBox 的 KeyUp 事件?

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 DomainDataSource 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2024-09-11 17:03:35

它对我有用如下。

您可以添加 DomainDataSource,但从代码后面控制它,而不是在 xaml 中声明:

DomainDataSource testDDS.DomainContext = context;
testDDS.QueryName = "GetEmployeesWithPositionQuery";
testDDS.Load;

然后,正如我在 在代码中设置 FilterDescriptor - C# Silverlight 4 WCF,您可以在代码后面创建一个 FilterDescriptor 并将其添加到您的 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);

希望这有帮助,

翻转

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文