XAML Button Content

The text displayed in an XAML button is set by the Content property (or so I believe).
What is the correct way to do something like....

if mButton.Content = "Press Me" then

The above doesn't work :(
Who is Participating?
nmarunConnect With a Mentor Commented:
Content holds an object. You have to call a .ToString() on it.

Try this:

if mButton.Content.ToString() = "Press Me" then

gt2847cSr. Security ConsultantCommented:
Not sure what you're trying to do...  what you have above appears to be trying to set the text of the button in an "if" statement.

This would set the text on the button:
mButton.Content = "Press me";

This would test to see if the text on the button is "Press me";
if(mButton.Content == "Press Me")
{ // do something }
DodsworthAuthor Commented:
I'm trying to test if the button's text is "Press Me" but it Errors as

Error      1      Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual' is not defined.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

gt2847cSr. Security ConsultantCommented:
Ah, VB, not C#...  Not my specialty, but...

Try this:
if mButton.Text.Equals("Press Me") then

if String.Equals(mButton.Text, "Press Me") then
DodsworthAuthor Commented:
There is no .text on an xaml button.  It's called Content as far as I can see.
gt2847cSr. Security ConsultantCommented:
You are correct...  being that I don't do VB (other than occasionally read it), I tested the code under forms which uses .Text...  Content is correct for XAML so:

If mButton.Content.Equals("Press Me") Then
     code goes here
End If
DodsworthAuthor Commented:
If mButton.Content.Equals("Press Me") Then does not fire :
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.