0
votes

I have button and custom template for it. In the template I have two buttons inside a grid. Each button has own custom template. Also I have a trigger IsMouseOver for this root grid. My goal is change style for both buttons when mouse is over. But TargetName attribute of Setter does not have access to nested controltemplate's controls.

<Button Style="{StaticResource DropDownStyle}" Content="Downloads"/>

<Style x:Key="DropDownStyle" TargetType="{x:Type Button}">
  ...
      <ControlTemplate TargetType="{x:Type Button}">
        <Grid x:Name="DropDownButtonPanel">
          ... 
          <Button Grid.Column="0" Content="{TemplateBinding Content}">
            <Button.Template>
              <ControlTemplate TargetType="Button">
                <Grid x:Name="BlackSection"/> 
              ...

          <Button Grid.Column="1" Click="OnButtonClick">
            <Button.Template>
              <ControlTemplate TargetType="Button">
                <Grid x:Name="GreenSection"/> 
              ...

        </Grid>
        <ControlTemplate.Triggers>
          <Trigger Property="IsMouseOver" Value="True" SourceName="DropDownButtonPanel">
            ...
          </Trigger>
        ...

How can I access elements from BlackSection and GreenSection in the ControlTemplate.Triggers. Just setter TargetName = "Name" is not useful.

PS. I use two buttons inside one to handle different Click events. Another solution will be a Click event for Grid element, but I also do not know how to do this.

Thanks in advance for any help!

1

1 Answers

1
votes

You can't. You may be able to alter certain aspects of the child buttons by applying a style.

However, this whole thing seems messy. A "Button" control is just that, something with two states (pressed or unpressed), and an optional command to be invoked when it is pressed. It sounds like you are trying to shoehorn more functionality into it. Can you explain further why you need two buttons on your template?