【发布时间】:2011-02-03 20:18:46
【问题描述】:
在我看来,我有一个按钮:
<Button Style="{StaticResource ButtonTextForwardStyle}" Content="My Text" Width="400" Height="100" />
在 app.xaml 中,我试图定义一个看起来像
的样式<ControlTemplate x:Key="ButtonTextForwardTemplate" TargetType="Button">
<Grid>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="Pressed"/>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
<Style x:Key="ButtonTextForwardStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="Pressed">
<Storyboard Storyboard.TargetName="image" Storyboard.TargetProperty="Source">
<ObjectAnimationUsingKeyFrames>
<DiscreteObjectKeyFrame KeyTime="0" Value="pressedimage.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<StackPanel Orientation="Horizontal">
<Image x:Name="image" Source="normalimage.png" Height="80" Width="100" Stretch="Fill" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Content}" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我希望将按钮的内容(我的文本)绑定到 TextBlock。但它看起来好像不起作用。
我该怎么做?
提前感谢您的帮助。
最好的问候
【问题讨论】:
标签: silverlight data-binding windows-phone-7