Hi
I want to implement two check boxes there are mutual exclusion. If box one are checked to true, box two must automatic turn to false. I have the two checkboxes in a dockpan.
This is what I have so far.
xaml:
<CheckBox
Margin="5"
Style="{DynamicResource Esri_CheckboxToggleSwitch}"
Name="CheckBox_One"
IsChecked="{Binding IsCheckedBoxOne}">
<TextBlock>
<Run Text="BoxOne"/>
</TextBlock>
</CheckBox>
<CheckBox
Margin="5"
Style="{DynamicResource Esri_CheckboxToggleSwitch}"
Name="CheckBox_Two"
IsChecked="{Binding IsCheckedBoxTwo}">
<TextBlock>
<Run Text="BoxTwo"/>
</TextBlock>
</CheckBox>
c#:
private bool _isCheckedBoxOne;
private bool _isCheckedBoxTwo;
public bool IsCheckedBoxOne
{
get { return _isCheckedBoxOne; }
set
{
SetProperty(ref _isCheckedBoxOne, value);
}
}
public bool IsCheckedBoxTwo
{
get { return _isCheckedBoxTwo; }
set
{
SetProperty(ref _isCheckedBoxTwo, value);
}
}
How to implement the logic?
Solved! Go to Solution.
If you implement your checkbox logic in the viewmodel as @GKmieliauskas suggests you have to prevent recursion when you set the counter property. Here is my suggestion (i attached a sample solution)
private bool _isCheckedOne;
private bool _isCheckedTwo;
public bool IsCheckedOne
{
get { return _isCheckedOne; }
set
{
SetProperty(ref _isCheckedOne, value);
if (IsCheckedTwo == IsCheckedOne)
{
// prevent recursion
IsCheckedTwo = !IsCheckedOne;
}
}
}
public bool IsCheckedTwo
{
get { return _isCheckedTwo; }
set
{
SetProperty(ref _isCheckedTwo, value);
if (IsCheckedOne == IsCheckedTwo)
{
// prevent recursion
IsCheckedOne = !IsCheckedTwo;
}
}
}
Hi,
There is no logic implemented in your code between IsCheckedOne and IsCheckedTwo properties.
private bool _isCheckedBoxOne;
private bool _isCheckedBoxTwo;
public bool IsCheckedBoxOne
{
get { return _isCheckedBoxOne; }
set
{
SetProperty(ref _isCheckedBoxOne, value);
_isCheckedBoxTwo = !_isCheckedBoxOne;
// Generate notification message here to update _isCheckBoxTwo, it could differ from that sample
OnPropertyChanged("IsCheckedBoxTwo");
}
}
public bool IsCheckedBoxTwo
{
get { return _isCheckedBoxTwo; }
set
{
SetProperty(ref _isCheckedBoxTwo, value);
_isCheckedBoxOne = !_isCheckedBoxTwo;
// Generate notification message here to update _isCheckBoxOne, it could differ from that sample
OnPropertyChanged("IsCheckedBoxOne");
}
}
It is enough one property for both controls, but you need to use boolean inverting converter in second property binding.
Question like yours is not a scope of ArcGIS Pro. It is WPF part.
If you implement your checkbox logic in the viewmodel as @GKmieliauskas suggests you have to prevent recursion when you set the counter property. Here is my suggestion (i attached a sample solution)
private bool _isCheckedOne;
private bool _isCheckedTwo;
public bool IsCheckedOne
{
get { return _isCheckedOne; }
set
{
SetProperty(ref _isCheckedOne, value);
if (IsCheckedTwo == IsCheckedOne)
{
// prevent recursion
IsCheckedTwo = !IsCheckedOne;
}
}
}
public bool IsCheckedTwo
{
get { return _isCheckedTwo; }
set
{
SetProperty(ref _isCheckedTwo, value);
if (IsCheckedOne == IsCheckedTwo)
{
// prevent recursion
IsCheckedOne = !IsCheckedTwo;
}
}
}
Hi, thanks for the answer both of you.
I try both, and it works for me.
@Wolf I tried the sample solution, but its target AGO 3.2 🙂
I changed the target in the daml-file and can run the souluton.