2015-05-29 31 views
1

我想創建一個按鈕,使用圖像作爲背景並在背景上放置我的文本。如何在WinRT中的按鈕中的圖像上放置文本

我想是這樣的:

<Button Style="{StaticResource ImageButtonStyle}"> 
    <StackPanel> 
     <TextBlock Text="test"></TextBlock> 
     <Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" /> 
    </StackPanel> 
</Button> 

文本將無法正確居中。

<Button Style="{StaticResource ImageButtonStyle}"> 
    <StackPanel> 
     <TextBlock Text="test"></TextBlock> 
     <Label Padding="0">My Button Text</Label> 
    </StackPanel> 
</Button> 

控件Label不存在。

如何在我第一次嘗試中正確地在圖像上居中顯示文字? 你知道更好的方法嗎?

回答

4

您應該使用網格框架的堆疊面板。嘗試這樣的:

<Button > 
     <Grid> 
      <Image Source="..." Stretch="None" /> 
      <TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/> 
     </Grid> 
    </Button> 
+0

謝謝,它的工作 –

相關問題