Basically I have a button that I built a control template for. It is currently working but VS 2010 complains about the following line of code in my control template
<TextBlock Text="{TemplateBinding Content}"
Foreground="{TemplateBinding Foreground}"
x:Name="cContentTextBlock" />
The control template is for a Button and I have a variety of VisualStates that target this TextBlock.
I can see why VS2010 complains... What if the content isn't actually text? This would cause problems. For me the big deal is that I want to set the Foreground of the text in response to Visual State changes.
Any ideas on how I could accomplish this? (try it, it works... but the vs2010 designer chokes on it)
The following is the entire style:
<Style x:Key="PassiveLinkButton" TargetType="Button">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="cMouseOverBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Black" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="cMouseOverBorder" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Blue" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="cContentTextBlock" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Blue" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Disabled"/>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Border x:Name="cFocusBorder"
BorderThickness="1"
BorderBrush="{StaticResource BorderBrush}"
Margin="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="cMouseOverBorder"
BorderBrush="Transparent" BorderThickness="0,0,0,1" Margin="0 0 0 2">
<StackPanel HorizontalAlignment="Left">
<TextBlock Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}"
x:Name="cContentTextBlock" Margin="2 2 2 0"
HorizontalAlignment="Center" />
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Which would be used like:
<Button Content="Press Me" Style={StaticResource PassiveButtonLink}" />