Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a button in F# that contains both an image and text?

I have both a button, and an image as follows:

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

I'd like the button content to contain some text, AND also the image.

I can do either of these two things just fine, but they don't get me both the text and the image on the button at the same time:

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

Neither of these things work:

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

I also can't set the background of the button to the image:

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

Any thoughts/ideas? Thanks!

like image 411
Mike Cialowicz Avatar asked Feb 26 '23 17:02

Mike Cialowicz


2 Answers

You can create StackPanel and add your image along with TextBlock as it's children. then set this stack panel as buttons content. You may choose some other Panel as well.

like image 117
alpha-mouse Avatar answered Feb 28 '23 06:02

alpha-mouse


You need to create a panel (probably a StackPanel with Orientation="Horizontal"). Set the content of the button to be the panel, and add the text and image to the panel.

like image 38
Guy Avatar answered Feb 28 '23 07:02

Guy