Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XAML Button Content

Posted on 2013-01-30
7
Medium Priority
?
424 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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