I am creating WPF elements dynamically in code behind, and for each of the rows in the Grid
I'm building it consists of a CheckBox
and a Dynamic number of TextBoxes
. The interaction that is needed is the following:
- If all
TextBoxes
in a row have a value of0
, set theCheckBox
IsChecked
property totrue
and Disable it. - If one of the
TextBoxes
is then changed from0
, enable theCheckBox
and setIsChecked
tofalse
. - If the user clicks on the
CheckBox
, set all associatedTextBoxes
to0
and Disable theCheckBox
I was able to accomplish the first part of the last one using this code:
Binding setScoreToZeroIfIsNormalChecked = new Binding("IsChecked");
setScoreToZeroIfIsNormalChecked.Source = this.NormalCheckBoxControl;
setScoreToZeroIfIsNormalChecked.Converter = m_NormalCheckBoxJointScoresConverter;
tempJointScoreControl.JointScoreContainer.SetBinding(ContainerBase.SingleAnswerProperty, setScoreToZeroIfIsNormalChecked);
and the converter:
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool && targetType == typeof(Answer))
{
if ((bool)value)
{
Answer answer = new Answer();
answer.Value = "0";
answer.DisplayValue = "0";
return answer;
}
else
return null;
}
else
{
return null;
}
}
However, in attempting to create another converter to accomplish other functionality, I was running into issues of converters stepping on one another since all functionality is based around the CheckBox.IsChecked
property.
Is there anyway to accomplish all of the above using one or two multibinding converters? I'd really like to avoid having to create a whole bunch of events and maintaining them in order to do this.
CheckBox.Click
andTextBox.TextChanged
events and adjust the values of the other objects in the code behind. You should only need two events, one for allCheckBoxes
and one for allTextBoxes
. Both can only affect items that share the sameGrid.Row
as the changed item. – Hayfork