【问题标题】:How to do that content of button show in the left in wp7?如何在 wp7 的左侧显示按钮的内容?
【发布时间】:2011-12-04 14:14:12
【问题描述】:

我有一个宽度为手机宽度的按钮,我希望按钮内容是左角的图像和图像后的文本,我将图像和文本放入堆栈面板、网格和画布并给出 HorizantalAllignment="Left" 但总是中心显示的内容,我该怎么做或我可以使用哪些其他控件,请帮助我

               <Border BorderThickness="0,0,0,2" BorderBrush="#FF479175">
                <Button Height="90" BorderThickness="0">
                    <Grid>
                        <Image Source="/HomePageDes;component/Images/main_news.png" Height="80" HorizontalAlignment="Left"  />
                        <TextBlock Text="News" />
                    </Grid>
                </Button>
            </Border>

【问题讨论】:

  • 请将您使用的 XAML 添加到问题中。帮助你会更容易。
  • 我也添加了一个网格示例,请查看我编辑的答案。

标签: silverlight windows-phone-7 button controls


【解决方案1】:

只需设置HorizontalContentAlignment="Stretch" on your button。默认为centre

然后带有HorizontalAlignment="Stretch" 的网格将满足您的需求。

【讨论】:

    【解决方案2】:

    我想这就是你要问的:

     <Button>
          <StackPanel Orientation="Horizontal">
            <Image src=""/>
            <TextBlock Text="ClickMe"/>
          </StackPaenl>
        </Botton>
    

    如果您使用 Grid 作为容器,则需要定义 Grid Columns 并将图像放在第 0 列,将文本放在第 1 列。在这种情况下更容易使用 Stackpanel。

    例如:

      <Button>
        <Grid HorizontalAlignment="Left">
           <Grid. ColumnDefinitions >
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="Auto"/>
           </Grid. ColumnDefinitions>
                    <Image Source="/HomePageDes;component/Images/main_news.png" Height="80" HorizontalAlignment="Left"  Grid.Column="0"/>
                     <TextBlock Text="News"  Grid.Column="1"/>
         </Grid>
       </Button>
    

    【讨论】:

    • 我不能没有容器,否则它说我设置了两次内容,我也使用了 stackpanel 或画布,但内容总是在中心
    • @Vahan:我的网格示例确实使用了容器。它的网格内部按钮。
    • @Vahan:只需将列定义添加到您的网格中即可。
    • 它一个接一个地显示,但又在中心而不是在左侧,如果不相信在你的comp上运行
    • @Vahan:将 Horizo​​ntalAlignment="Left" 添加到网格中。我看你已经解决了吗?
    猜你喜欢
    • 2015-07-18
    • 2011-06-09
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多