こんにちは私は、ボタンをクリックするとバスケットに整数値を渡そうとしています。私はこのメソッドを使って文字列を渡すことに成功しましたが、数値ではできませんでした。ボタンをクリックすると、ログオーダーからバスケットに移動すると、バスケットページのテキストボックスに数字「1」が表示されます。代わりに、私が必要としていたデザインで0に設定するたびに、テキストボックスに0が表示されます。そうしないと、プログラムを実行するときにエラーが表示されます。app.csを使用して別のページに整数を渡すことはできません。Windows phone
はいテキストボックスを整数に変換し、テキストボックスの値を「0」に設定しました。
私はapp.cs.で変数 "storevalue"を初期化しました。
これは、次のページのテキストボックスに表示される整数を初期化するボタンを持つログオーダーのコードです。最初のテキストボックスに表示に整数を示すべきである2ページ目の
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace icecreamapp
{
public sealed partial class logorder : Page
{
public logorder()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void button_Click(object sender, RoutedEventArgs e)
{
App app = Application.Current as App;
app.storeValue = 1; //initializing variable as 1
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(basket)); //button that navigates to next page
}
}
}
コード...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace icecreamapp
{
public sealed partial class basket : Page
{
App app = Application.Current as App;
public basket()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
App app = Application.Current as App;
var v = int.Parse(textBox.Text); //converting textbox to integer
v = app.storeValue; //variable should be displayed in this textbox and show "1"
}
private void button_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(logorder));
}
private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
}
}
ありませんあなたの希望する値に。あなたは何らかのバインディングをしていますか? –