Trying to build a Query Builder Control in WPF

2019-03-31 18:25发布

Please bear with me for the length of this question, I tried to be as descriptive as possible. I am new to WPF programming. I am basically trying to build the RadDataFilter control:

RadDataFilter is used to filter collection by building query expression. The control is generally used by bringing all data from the database and then filtering on them.

However, I am trying to use it to build SQL query expression and then I query the database to retrieve the data. Our company has license for Telerik products so I had to try and use the control. Unfortunately, the control is not flexible to the extent that I would want to customize the Left Dropdown (RadComboBox).

As we have several items which users can filter on, it is not feasible to provide them with a single dropdpwn. I would like to have a custom control instead of the dropdown.

I have the following workaround to this problem:

  • Extract the Template for that control and override it in my XAML as described here. However, inspite of doing this, I am unable to change the control. I assume it is due to my inadequate knowledge in WPF.

  • Try to change the Source code for Telerik (We have the license for the code too). However with this approach, we need to keep making changes with every upgrade, which is high maintenance for the team.

  • Try to build a custom control.

I am looking for the 3rd approach. If there is an easy way (using the first 2 approaches) or any other solution to achieve this, please let me know and I shall try that.

To implement the 3rd approach, I am thinking to use a TreeView with each node using a ControlTemplate (containing my Custom Control). I will override the ToString() method of the Custom Control that gives me the one query condition. Once done, I would iterate through the children of the root node to build the final query expression.

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!

1条回答
对你真心纯属浪费
2楼-- · 2019-03-31 19:18

I resolved it. Took the first approach:

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

查看更多
登录 后发表回答