2011-12-06 21 views
0

我有一個按鈕的樣式與控件模板像這樣讀一個Button的Content屬性到一個風格ConrtolTemplate

<Style x:Key="ButtonStyle" 
       BasedOn="{x:Null}" 
       TargetType="{x:Type Button}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <Grid> 
        <Rectangle x:Name="rectangle" 
           Fill="#FF04822A" 
           Stroke="{x:Null}" /> 
        <TextBlock HorizontalAlignment="Center" 
           VerticalAlignment="Center" 
           FontWeight="Heavy" 
           Foreground="Black" 
           x:Name="btnText" 
           TextAlignment="Center" /> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
<Button Grid.Row="3" 
       Grid.Column="5" 
       Margin="4,0,4,0" 
       Command="{Binding ResetCommand}" 
       Content ="Reset Cells" 
       Style="{StaticResource ButtonStyle}" /> 

我想將TextBlock每次都從按鈕的內容讀其更新。

回答

3

添加模板綁定到TextBlock

Text="{TemplateBinding Content}" 

你可能只是想使用一個ContentPresenter雖然代替(如TextBlocks通常只顯示文本)。