Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Help -- Using {TemplateBinding Content} withTextBlock in ControlTemplate
5 replies. Latest Post by Min-Hong Tang - MSFT on November 13, 2009.
(0)
berandor...
Member
6 points
9 Posts
11-04-2009 12:13 PM |
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>
Ardman
Contributor
3436 points
947 Posts
11-04-2009 12:26 PM |
Are you using Beta 2 Visual Studio 2010?
11-04-2009 4:26 PM |
The error was generated with VS 2010 Beta 2. I am under the impression the error is correct but perhaps I am not right in this.
Min-Hong...
3619 points
412 Posts
11-11-2009 3:58 AM |
Hi,
Thanks a lot for notifing this issue. I have reported to visual studio team.
Deeply sorry if it caused you any trouble.
Best Regards
11-11-2009 12:05 PM |
Hi Min-Hong,
So you believe my syntax is OK but it is an error in VS2010? I ask because I am trying to determine if I need to not follow this particular practice.
Thanks !
11-13-2009 2:10 AM |
Hi Berandor,
I test it in VS2008 both the desin view and the program works fine. And in vs2010 the program also works fine but the design view gives us an exception.