2010-12-01 45 views
4

我有兩個按鈕,以及相關圖片如下:如何在包含圖像和文本的F#中創建按鈕?

let btnFoo = new Button() 
let imgBar = new BitmapImage(new System.Uri("images/whatever.png", System.UriKind.RelativeOrAbsolute)) 

我想按鈕的內容包含一些文本,也形象。

我可以做任何的這兩件事情就好了,但他們沒有得到我的都在同一時間上的按鈕文本和圖像:

btnFoo.Content <- "Text" 
btnFoo.Content <- imgBar 

這些都不事情工作:

btnFoo.Content <- "Text " + imgBar // compiler hates this 
btnFoo.Content <- "Text ", imgBar // compiler is OK, but result is ugly since the image is rendered as the class text 

我也不能設置按鈕,以圖片的背景:

btnFoo.Background <- imgBar // compiler doesn't like this because Background expects a Media.Brush 

任何思想S /想法?謝謝!

回答

5

您可以創建StackPanel並將您的圖像與TextBlock一起添加爲孩子。然後將此堆棧面板設置爲按鈕內容。您也可以選擇其他一些Panel

+0

非常好,謝謝。 – 2010-12-01 17:56:26

3

您需要創建一個面板(可能是一個方向=「水平」的StackPanel)。將按鈕的內容設置爲面板,並將文本和圖像添加到面板。

相關問題