This is a migrated thread and some comments may be shown as answers.

Logical Operator button

7 Answers 153 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
gordon
Top achievements
Rank 1
gordon asked on 23 Dec 2017, 05:35 PM
Is it possible to change the logical operator button to two radio buttons?

7 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 27 Dec 2017, 01:23 PM
Hello Gordon,

You may be able to achieve the desired result by modifying the control template of the FilterControl element. I've attached a small sample project to demonstrate a possible approach, however, bear in mind that this may not cover all use cases of the control.

What I've done is to replace the RadToggleButton with the following RadioButtons and handled their Checked event in the following fashion:

<RadioButton Content="And" GroupName="LogicalOperators" Checked="RadioButton_Checked" />
<RadioButton Content="Or" GroupName="LogicalOperators" Checked="RadioButton_Checked" />

private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
    var button = sender as RadioButton;
    var vm = button.DataContext as FilterViewModel;
    vm.CompositeFilter.LogicalOperator = button.Content.ToString() == "And" ? Telerik.Windows.Data.FilterCompositionLogicalOperator.And : Telerik.Windows.Data.FilterCompositionLogicalOperator.Or;
}

Please let me know whether you find such an approach applicable.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
gordon
Top achievements
Rank 1
answered on 27 Dec 2017, 07:40 PM

Thanks Dilyan,

Your solution works for me.  I have an additional question.  I have a scenario where I bind the FilterDescriptors to an observable collection.  I need to bind the LogicalOperator too, or at least set it initially.  I have CanUserCreateCompositeFilters="False" for the RadDataFilter, so there is only one LogicalOperator.

 

0
Dilyan Traykov
Telerik team
answered on 28 Dec 2017, 01:46 PM
Hello Gordon,

You can access the logical operator of the control through its ViewModel.CompositeFilter.LogicalOperator property.

this.radDataFilter.ViewModel.CompositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
gordon
Top achievements
Rank 1
answered on 28 Dec 2017, 06:19 PM

I changed the xaml to

<RadioButton Content="And" GroupName="LogicalOperators" Checked="RadioButton_Checked" IsChecked="{Binding CompositeFilter.LogicalOperator, Mode=TwoWay, Converter={StaticResource LogicalOperatorToCheckedConverter}}"/>
<RadioButton Content="Or" GroupName="LogicalOperators" Checked="RadioButton_Checked" />

and added

this.radDataFilter.ViewModel.CompositeFilter.LogicalOperator = FilterCompositionLogicalOperator.And;

to MainWIndow constructor.  The "And" radio button is initially checked, but when I click on the "+" button, the "And" button gets unchecked.

Without the binding on the radiobutton, setting this.radDataFilter.ViewModel.CompositeFilter.LogicalOperator = FilterCompositionLogicalOperator.And does nothing, of course.

 

So how do i bind the radio buttons such that i set their initial value, and maintain the selection?

Thanks.

0
Stefan
Telerik team
answered on 02 Jan 2018, 02:31 PM
Hi Gordon,

Thank you for the update.

This behavior is most probably due to the ConvertBack method of the LogicalOperatorToCheckedConverter IValueConverter. However, instead of using binding and an IValueConveter, may I suggest you a slightly different approach? You should be able to achieve the same result by simply setting the IsChecked property of the And RadioButton initially to True. Thus, the selection of will be persisted when adding the new filtering criteria. Synchronizing the CompositeFilter.LogicalOperator with the selection performed in the UI can be further handled through the Checked/UnChecked events, as demonstrated by my colleague. Would such an approach be feasible for you?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
gordon
Top achievements
Rank 1
answered on 03 Jan 2018, 11:39 PM

Hi Stefan,

Your approach works if I hard wire the IsChecked property in the xaml.  The problem is I need to set it at runtime depending on a value in my model.  I am not sure how to use your approach in this scenario.  Thanks.

0
Stefan
Telerik team
answered on 08 Jan 2018, 10:58 AM
Hi Gordon,

Thanks for the update.

Indeed, for such requirement the data binding approach would be more appropriate, but handling both "And" and "Or" scenarios in the ConvertBack method of the IValueConverter would hardly be implemented so that the selection is persisted. Thus, a possible solution for achieving the desired customization would be to access the RadioButtons in code and set their IsChecked property manually when needed.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
DataFilter
Asked by
gordon
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
gordon
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or