Solved

XAML Button Content

Posted on 2013-01-30
7
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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