0
<VisualState x:Name="MouseOver">
    <Storyboard>
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" 
                                        Storyboard.TargetProperty="Fill">
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource 
                                        ButtonHoverBackgroundBrush}" />
          </ObjectAnimationUsingKeyFrames>
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" 
                                         Storyboard.TargetProperty="Stroke">
               <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource 
                                                   ButtonHoverBorderBrush}" />
          </ObjectAnimationUsingKeyFrames>
          <ObjectAnimationUsingKeyFrames Duration="0" 
                                         Storyboard.TargetProperty="Foreground" 
                                         Storyboard.TargetName="ContentControl">
               <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource 
                                                   LightForegroundBrush}" />
         </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

Instead of going Storyboard.TargetName=ContentControl and Storyboard.TargetProperty=Foreground, i would like to Animate the templated parent's foreground, and the content control to just have it's foreground property binded to the templated parent

Foreground={TemplateBinding Foreground}

The reason for this is that when i use the control with this template, i want to be able to do :

<Button Width="125"
        Height="30"
        Click="OnButtonClick"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Margin="50,54,0,0">
        <Button.Content>
            <controls:SomeCustomControl '
                             Foreground="{Binding Path=Foreground, 
                             RelativeSource={RelativeSource AncestorType=
                             {x:Type Button}}}" />                   
        </Button.Content>
</Button>

I tried doing :

<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.Target="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}" />
</ObjectAnimationUsingKeyFrames>

however this crashes. Any suggestions on how this can be done? Thanks in advance.

Andrei
  • 11
  • 2

1 Answers1

0

Same Problem on my Side ....

But it could be that we just thought in the wrong way.

It is "Content" to be styled but no one knows what Content it would be. So the "right" way would be to say that its the work for the Control you put into the Content.

Example, if you put a Button into a ContentControl, the Button style handle the VSM not the ContentControl around it.

That ist not the exactly answer to your question but maybe some help to understand why this isn´t some option.

Edit: After some research i found this:

Animating a TextBox.Foreground in WPF

It feels not the best practice but it could be work for your problem.

Cogeck
  • 76
  • 9