locked
Accessing Input Data in Code RRS feed

  • Question

  • Hi,

    I'm designing a UI for some scientific software. I wish to press a button to run a simulator which will use numerical data input in a text box. I thought of one way to do it - on clicking enter in the text box, the routine stores the data to file.

    But i presume if my 'run' button links to my c# code file to do the sim, this file can access the data from the window text box?

    How can i do this?

    Thanks.

    Wednesday, May 7, 2008 12:49 PM

Answers

  • Howdy,

    As long as you name the textbox in Blend, your C# has access to its value in code..

    Example

    1. Name a textbox... "txtDataInput"
    2. On the button click, in the click event handler in code:

    (lets say you want a double)

    double NewValue = Convert.ToDouble(this.txtDataInput.Text);


    You need to remember the data type in the textbox is a string so your will need to convert it to a relevant numerical type. You should also research doing validation on the user entry to make sure it is a valid number etc..

    HTH


    Cheers
    Learn Expression Blend at learnexpressionstudio.com
    Wednesday, May 7, 2008 11:26 PM
    Moderator

All replies

  • Howdy,

    As long as you name the textbox in Blend, your C# has access to its value in code..

    Example

    1. Name a textbox... "txtDataInput"
    2. On the button click, in the click event handler in code:

    (lets say you want a double)

    double NewValue = Convert.ToDouble(this.txtDataInput.Text);


    You need to remember the data type in the textbox is a string so your will need to convert it to a relevant numerical type. You should also research doing validation on the user entry to make sure it is a valid number etc..

    HTH


    Cheers
    Learn Expression Blend at learnexpressionstudio.com
    Wednesday, May 7, 2008 11:26 PM
    Moderator
  • Perfect.

    Thanks a lot.

    Just a quick follow up question.

    'this' refers to the window or app object class?

    (I'm currently in the process of learning C# - so its a little rusty).

    Everything else makes perfect sense and i should be able to build my app.

    Thanks again

    Thursday, May 8, 2008 8:26 AM
  • In this case this refers to the Windows instance.
    Corrado Cavalli [MVP]
    Thursday, May 8, 2008 8:00 PM