2011-02-03 56 views
2

在我看來,我有一個按鈕:綁定到我的WP7 Silverlight應用程序的風格

<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。但看起來它不起作用。

我該怎麼做?

在此先感謝您的幫助。

問候

回答

3

你TextBlock的是按鈕控件模板內,所以你可能需要使用的,而不是綁定TemplateBinding。

<TextBlock Text="{TemplateBinding Content}" 
+0

它的工作,謝謝:) – Tim 2011-02-03 20:41:26