Convert textbox text to integer

前端 未结 5 1548
感情败类
感情败类 2020-12-09 06:28

I need to convert the text in the textbox of my xaml code to an integer value in C#. I am using .NET 4.0 and Visual Studio 2010. Is there a way to do it in xaml tags itself

5条回答
  •  暖寄归人
    2020-12-09 07:32

    You don't need to write a converter, just do this in your handler/codebehind:

    int i = Convert.ToInt32(txtMyTextBox.Text);
    

    OR

    int i = int.Parse(txtMyTextBox.Text);
    

    The Text property of your textbox is a String type, so you have to perform the conversion in the code.

提交回复
热议问题