-1
當我從另一個xaml(菜單)中選擇項目時,我想要做的事情基本上是在一個xaml(Basket)中填充項目名稱的文本框。我的代碼如下:如何填充文本框-Windows Phone 8.1
Menu.xaml
在這裏,當我點擊一個按鈕,我希望它automaticallly出現在Basket.xaml一個文本框。
public class PassedData
{
public string Name { get; set; }
public int Value { get; set; }
}
private void Vanbtn_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Basket), new PassedData { Name = "Cheese" });
}
private void LCbtn_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Basket), new PassedData { Name = "Crisp" });
}
Basket.xaml
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Menu.PassedData data = e.Parameter as Menu.PassedData;
/** ItemChosentxt.Text = data.Name;
ItemChosentxt2.Text = data.Name;
ItemChosentxt3.Text = data.Name;
ItemChosentxt4.Text = data.Name;**/
}
的註釋部分增加了選擇的項目的名稱。而不是僅僅添加到一個文本框就會添加到所有的文本框中。即如果我在Menu.xaml中選擇了vanilla btn,則名稱將出現在所有4個文本框中,而不僅僅是一個。所以,我決定實施每個文本框代碼:
private void ItemChosentxt_TextChanged(object sender, TextChangedEventArgs e)
{
Menu.PassedData data = e.Parameter as Menu.PassedData;
ItemChosentxt.Text = data.Name;
}
private void SecItem_TextChanged(object sender, TextChangedEventArgs e)
{
Menu.PassedData data = e.Parameter as Menu.PassedData;
SecItem.Text = data.Name;
}
這顯示一個錯誤的e.Parameter下面的錯誤代碼是 -
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'data' does not exist in the current context
和
Severity Code Description Project File Line Suppression State
Error CS1061 'TextChangedEventArgs' does not contain a definition for 'Parameter' and no extension method 'Parameter' accepting a first argument of type 'TextChangedEventArgs' could be found (are you missing a using directive or an assembly reference?)
我正在開發一個購物應用程序,例如如果用戶從菜單中選擇「香草」和「蛋糕」,我該如何讓名稱顯示在籃子文本框中?我對應用程序開發不熟悉,並對長期問題表示歉意。