2010-12-01 59 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)。将按钮的内容设置为面板,并将文本和图像添加到面板。

相关问题