Windows手机 - 如何制作具有两个文本元素的按钮

时间:2014-07-15 09:45:32

标签: windows-phone-7 button windows-phone-8

我想知道制作一个包含两个文本元素的按钮的最简单/最好的方法是什么。一个在左侧,另一个在右侧。

example

首先我想把一个TextBlock放在一个Button的顶部,但TextBlock应该改变颜色,就像Button按下按钮时的文本一样。我还没有找到办法完美地做到这一点另外,我想要一个更顺畅的解决方案。

我应该继承Button并制作我自己的版本吗?是否有一些示例或教程可以帮助解决这个问题?

我之前没想过用Windows Phone做过很多事情,你可能会猜到。

1 个答案:

答案 0 :(得分:2)

您的案例中有几种变体

  1. 将具有两个TextBlocks的Container放在Button

    <Button>
      <Grid>
        <Grid.ColumnDefenitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefenitions>
        <TextBlock Text="TIME"/>
        <TextBlock Text="2:20" Grid.Column="1" HorizontalAlignment="Right"/>
      </Grid>
    </Button>
    
  2. 如果使用Binding

    ,另一种选择是使用StringFormat
    <Button Content="{Binding time, StringFormat={}TIME {0:t}}"" />