-1

I would like to achieve something in wpf which not seems to be easy to me. I want to change the outer border's CornerRadius depending on the inner element's state. If the ToggleButton's IsChecked property is true then change the CornerRadius of the outer element something different than the default one.

I tried - among a lot of other things - this:

<Border x:Name="rootElement"
      CornerRadius="5">
      <ToggleButton
          x:Name="showAdditionalOptions">
          ...
      </ToggleButton>
    <Border.Style>
      <Style TargetType="{x:Type Border}">
          <Style.Triggers>
              <DataTrigger Binding="{Binding IsChecked, ElementName=showAdditionalOptions}" Value="True">
                  <Setter Property="CornerRadius" Value="0"/>
              </DataTrigger>
          </Style.Triggers>
      </Style>
     </Border.Style>
 </Border>

I want to change the CornerRadius of rootElements if IsChecked is true for showAdditionalOptions. I tried setting the trigger in the ToggleButtons Triggers parts (both Style.Triggers AND Template.Triggers) but from there I can't reach outer elements (TargetName does not work).

Clemens
  • 123,504
  • 12
  • 155
  • 268

1 Answers1

0

I found out what is the problem, but I don't delete the question because trickier than it seems. The trigger works well. When I changed the Visibility of the same item (rootElement) to collapsed then it really collapsed. It turned out that the following line overwrites every trigger action:

CornerRadius="5"

Since it is set to 5 (5,5,5,5) nothing happened after the trigger finished running. Instead of setting the CornerRadius on the very object, the following code shall be used:

<Border x:Name="rootElement">
    <ToggleButton
        x:Name="showAdditionalOptions">
        ...
    </ToggleButton>
    <Border.Style>
        <Style TargetType="{x:Type Border}">
            <!-- Set default CornerRadius here! -->
            <Setter Property="CornerRadius" Value="5"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsChecked, ElementName=showAdditionalOptions}" Value="True">
                    <Setter Property="CornerRadius" Value="0"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
</Border>