Simple and effective way to convert int to string (and back) in C++/CX XAML Windows Store App

This post provides you a simple way to convert int to string and back in c++/cx XAML (using textbox)

your .xaml file

<StackPanel>
<TextBlock Name=”tbNumberOne”>First Number</TextBlock>
<TextBox x:Name=”inputOne”></TextBox>
<TextBlock Name=”tbNumberTwo”>Second Number</TextBlock>
<TextBox x:Name=”inputTwo”></TextBox>
<Button Content=”Add” Name=”btnAdd” Click=”btnAdd_Click_1″></Button>
<TextBlock Name=”tbResult”></TextBlock>
</StackPanel>

the .cs file

 

void App1Cpp::MainPage::btnAdd_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

{

int firstnumber = _wtoi(inputOne->Text->Data());

int secondnumber =_wtoi(inputTwo->Text->Data());  int result = firstnumber + secondnumber;

tbResult->Text = result.ToString();

}

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s