Solved

XAML Button Content

Posted on 2013-01-30
7
409 Views
Last Modified: 2013-01-31
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 :(
0
Comment
Question by:Dodsworth
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:gt2847c
ID: 38835223
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 }
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 38835585
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.
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 38835614
Ah, VB, not C#...  Not my specialty, but...

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

Or
if String.Equals(mButton.Text, "Press Me") then
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:Dodsworth
ID: 38835743
There is no .text on an xaml button.  It's called Content as far as I can see.
0
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 38835783
Content holds an object. You have to call a .ToString() on it.

Try this:

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

Arun
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 38835787
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
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 38838886
If mButton.Content.Equals("Press Me") Then does not fire :
(
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C#.NET and microsoft certification. 3 42
ASP.NET MVC 2 32
Get number of Files in Directory and Sub Directories 2 42
MailAddress in vb 4 17
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question