2 Replies - 5599 Views - Last Post: 18 December 2013 - 06:22 AM Rate Topic: -----

#1 charlay13  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 23-August 13

Working with numbers entered in textbox

Posted 17 December 2013 - 07:30 PM

Hello, I am trying to reference some textbox input provided by the user in my wpf. The input will always be numbers and my problem is when I refer to the textbox by it's name, it shows the error

"Cannot convert from 'System.Windows.Controls.TextBox' to 'double'"

The information inputted into the textbox will be numbers but my guess is that the compiler automatically thinks it's going to be letters in a string. That would be my best guess. Is there a specific way you can allow the textbox to accept and "work with" numbers?

If seeing some code would help please ask.
Thanks

Or do I need to refer to a different property of the TextBox besides its name?

Is This A Good Question/Topic? 0
  • +

Replies To: Working with numbers entered in textbox

#2 laytonsdad  Icon User is offline

  • Let it rip!
  • member icon

Reputation: 466
  • View blog
  • Posts: 1,991
  • Joined: 30-April 10

Re: Working with numbers entered in textbox

Posted 17 December 2013 - 07:43 PM

Where is your code?
Post relevant code inside [ code ] tags.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6504
  • View blog
  • Posts: 14,355
  • Joined: 02-June 10

Re: Working with numbers entered in textbox

Posted 18 December 2013 - 06:22 AM

Quote

Hello, I am trying to reference some textbox input provided by the user in my wpf. The input will always be numbers and my problem is when I refer to the textbox by it's name, it shows the error


No. The problem is you're trying to code WPF like it was WinForms.
Your textbox probably doesn't even need a name. If you are naming your controls in WPF its a good chance something is wrong.

The TextBox.Text property should be bound to a property in your code-behind. Your C# should always be using the C# property, never directly accessing the textbox.

Next you shouldn't be using a regular textbox for numeric-only input. Use a numbertextbox. Google "WPF Numeric TextBox" and you'll get lots of how-to article on how to make it.

Lastly, there are a couple articles linked in my signature block for "WPF for the WinForms coder". You should work them. And probably pick up a book on introduction to WPF. There is no point going forward like there, where you are trying to use WPF like WinForms. You won't gain 5% of the benefits that WPF has to offer like this.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1