大家好我是应用程序开发的新手,并且想知道如何将包含值的文本框传输到另一个页面。我的代码如下:
购物篮按钮
private void Confirm_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Confirmation) , Totaltxt_TextChanged = TotalValue);
}
需要将信息发送到
的OnNav protected override void OnNavigatedTo(NavigationEventArgs e)
{
Basket Basket = e.Parameter as Basket;
if (Basket != null)
{
COsttxt.Text = string.Format("{0:C}", Basket.Totaltxt_TextChanged);
}
}
我尝试过只使用TotalValue这是需要发送的主要值,但这似乎有效我甚至将它设置在NavTo页面的文本框中:
<TextBox x:Name="COsttxt" HorizontalAlignment="Left" Height="58" Margin="229,258,0,0" TextWrapping="Wrap" Text="{Binding TotalValue}" VerticalAlignment="Top" Width="131" TextChanged="COsttxt_TextChanged"/>
那么有没有办法从Basket.xaml发送Totaltxt文本框并使文本框值显示在Confirmation.xaml中?
答案 0 :(得分:0)
您正在将参数传递给确认页面,我确信该页面不属于篮子类型,因此当您进行as
转换时,您将获得null。
你应该这样简单地传递/阅读TotalValue:
private void Confirm_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Confirmation) , TotalValue);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var totalValue = e.Parameter as string; // or 'as' whatever is type of TotalValue
if (totalValue != null)
{
COsttxt.Text = string.Format("{0:C}", totalValue);
}
}
修改:传递最终文本框值,如下所示,并保持其余代码相同:
Frame.Navigate(typeof(Confirmation) , textboxName.Text);