Reputation: 5
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
Reputation: 66
I guess this is what you're looking for:
string buttonContent = ((Button)FindName("Button1"))?.Content.ToString();
Upvotes: 0
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
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