3

请耐心等待这个问题的长度,我试图尽可能地描述。我是 WPF 编程的新手。我基本上是在尝试构建RadDataFilter 控件

RadDataFilter 用于通过构建查询表达式来过滤集合。该控件通常通过从数据库中获取所有数据然后对其进行过滤来使用。

但是,我正在尝试使用它来构建 SQL 查询表达式,然后查询数据库以检索数据。我们公司有 Telerik 产品的许可证,所以我不得不尝试使用该控件。不幸的是,该控件不灵活,以至于我想自定义左下拉菜单(RadComboBox)。

由于我们有几个用户可以过滤的项目,因此为他们提供单个 dropdpwn 是不可行的。我想要一个自定义控件而不是下拉菜单。

对于这个问题,我有以下解决方法:

  • 提取该控件的模板并在我的 XAML 中覆盖它,如此处所述。但是,尽管这样做,我无法更改控件。我认为这是由于我对 WPF 的了解不足。

  • 尝试更改 Telerik 的源代码(我们也有代码的许可证)。然而,使用这种方法,我们需要在每次升级时不断进行更改,这对团队来说是高维护成本。

  • 尝试构建自定义控件。

我正在寻找第三种方法。如果有一种简单的方法(使用前两种方法)或任何其他解决方案来实现这一点,请告诉我,我会尝试的。

为了实现第三种方法,我正在考虑使用一个 TreeView,每个节点使用一个 ControlTemplate(包含我的自定义控件)。我将覆盖ToString()给我一个查询条件的自定义控件的方法。完成后,我将遍历根节点的子节点以构建最终的查询表达式。

However as I notice, we need 2 different ControlTemplates (one which allows creating a filter expression and the other with the operator, similar to RadDataFilter). I do not know how to set multiple templates like this.

This may sound simple to some of the developers out there, but I am really new to C# and WPF programming and would need time and experience to be comfortable with it.

Please let me know if you know any other solution that I can try to solve this problem. If you feel it is better to create a custom control, please guide me on whats the best way to implement this. Also comment on my approach to create the custom control.

Thanks!

4

1 回答 1

1

I resolved it. Took the first approach:

"Extract the Template for that control and override it in my XAML as described here.."

于 2012-08-16T16:56:10.017 回答