Kris Harper Kris Harper - 2 months ago 16
C# Question

Set IsEnabled for nested LayoutGroup based on property of parent

I have a radio button control and some dependent controls that I would like to be enabled or disabled based on which radio button is selected.

To do this, I'm trying to bind

IsEnabled
on the
LayoutGroup
s with
{Binding IsSelected, ElementName=radioButtonControlName}
. It is not working though.

My XAML looks like this

<Grid>
<dxlc:LayoutGroup Orientation="Horizontal">
<dxe:ListBoxEdit ShowBorder="False" StyleSettings="{dxe:RadioListBoxEditStyleSettings}" HorizontalContentAlignment="Stretch">
<dxe:ListBoxEditItem Name="radioButtonA" IsSelected="{Binding IsASelected, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
<dxlc:LayoutGroup>
<dxlc:LayoutItem Label="A">
<dxlc:LayoutGroup Name="aLayoutGroup" IsEnabled="{Binding IsSelected, ElementName=radioButtonA}">
<dxlc:LayoutItem Label="Date A">
<dxe:DateEdit EditValue="{Binding DateA, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Text A">
<dxe:TextEdit EditValue="{Binding TextA, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxe:ListBoxEditItem>
<dxe:ListBoxEditItem Name="radioButtonB" IsSelected="{Binding IsASelected, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
<dxlc:LayoutGroup>
<dxlc:LayoutItem Label="B">
<dxlc:LayoutGroup Name="bLayoutGroup" IsEnabled="{Binding IsSelected, ElementName=radioButtonB}">
<dxlc:LayoutItem Label="Date B">
<dxe:DateEdit EditValue="{Binding DateB, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Text B">
<dxe:TextEdit EditValue="{Binding TextB, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxe:ListBoxEditItem>
</dxe:ListBoxEdit>
</dxlc:LayoutGroup>
</Grid>


Incidentally, if I move the
LayoutGroup
s outside of the
ListBoxEdit
control, it works as expected. The problem then is that I don't know how to align the radio buttons with the dependent controls. If someone can help me align those properly, then that solution would work as well, I think.

Answer

Since I am not dynamically generating the radio buttons, I decided to not use a ListBoxEdit and instead just put RadioButton elements in my layout. I needed to change the IsSelected binding to IsChecked, but other than that it works pretty much the same way.