BartTed
BartTed

Reputation: 5

How to get the content of the selected button

I am looking for a JavaScript equivalent

document.getElementById("Button").innerHTML

in C # WPF.

I need to get button content by x:Name

Upvotes: 0

Views: 159

Answers (3)

Overlord
Overlord

Reputation: 66

I guess this is what you're looking for:

string buttonContent = ((Button)FindName("Button1"))?.Content.ToString();

Upvotes: 0

Rans
Rans

Reputation: 602

You can do this in the code behind (e.g. myView.xaml.cs) of your xaml (e.g. myView.xaml) file.

Something like this

string text = Button1.Content.ToString();

Upvotes: 1

Mark Feldman
Mark Feldman

Reputation: 16148

Welcome to SO.

If the button is an element on the page and has the name "myButton" then you can access its content from within the parent class as myButton.Content.

Upvotes: 0

Related Questions