S
S
Space Purr2020-01-11 00:41:27
WPF
Space Purr, 2020-01-11 00:41:27

How to change a property of a parent element with a trigger?

Hello.
There is an Expander element with a nested PopUp (to be on top of other elements), inside the PopUp there is a StackPanel with three RadioButtons united by one GroupName.
I will omit some properties in the code so that it is closer to the point:

<Expander Name="MyExpander" ... IsExpanded="False" >
     <PopUp ... StaysOpen="False" IsOpen="{Binding ElementName=MyExpander, Path=IsExpanded}" >
          <StackPanel>
               <RadioButton GroupName="Group" Name="First"/>
               <RadioButton GroupName="Group" Name="Second"/>
               <RadioButton GroupName="Group" Name="Third"/>
          </StackPanel>
     </PopUp>
</Expander>

The IsOpen property of the PopUp element is bound to the IsExpanded property of the Expander element, that is, when you click on the Expander arrow, PopUp opens, and when you click on an empty space, the PopUp closes and the Expander arrow changes to a closed one.
I need that when I click on one of the RadioButtons, my Expander also closes.
I tried to implement this via Trigger IsPressed on the RadioButton, but I couldn't hook up to the element's MyExpander property, because Property doesn't allow Binding to be used.
I know that I can do this in the ViewModel by binding one property to both IsExpanded and IsOpen and change it in the Command of each RadioButton, but I wonder if it is possible to implement this only in xaml.
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question