7 Answers, 1 is accepted
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
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.
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
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.
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
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.
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