How to pass an object from a Frame to another Frame in a Windows 8 Style App(如何在 Windows 8 样式应用程序中将对象从框架传递到另一个框架)
问题描述
我有一个问题,我现在无法弄清楚.我正在尝试开发一个 Windows-8 风格的应用程序,但我坚持实现此功能.
I have problem that i just cant figure out right now. I am trying to develop a Windows-8 style app and im stuck implementing this functionality.
我有一个 MainWindow,其中包含一个 ListBox 和一个按钮(比如说 addButton).
I have a MainWindow which contains a ListBox and a Button (lets say addButton).
当我点击按钮时,我导航到一个新页面,让我们说 AddCustomerPage with this.Frame.Navigate(typeof (AddCustomerPage));
When i click the button i navigate to a new page, lets say AddCustomerPage with this.Frame.Navigate(typeof (AddCustomerPage));
AddCustomerPage 有 1 个文本框和 1 个按钮(可以说 doneButton.当我单击按钮时,我希望将文本框中的字符串添加到上一个列表框中页面.
AddCustomerPage has 1 textBox and 1 button (lets say doneButton. When i click the button i want the string in the textBox to be added to the ListBox on the previous page.
这是我目前的功能:1. 创建主窗口.
This is my current functionality: 1. MainWindow is created.
点击添加按钮
Click addButton
AddCustomer 页面已创建.MainWindow 被破坏(问题).
AddCustomer page is created. MainWindow is destroyed(problem).
点击完成按钮
一个 MainWindow 对象是用一个有 1 个项目的 ListBox 创建的.
A MainWindow object is created with a ListBox with 1 item.
重复添加过程,我总是得到一个带有 1 个项目的 ListBox 的 MainWindow.
Repeat the add process, i always get a MainWindow with a ListBox with 1 item.
感谢您的帮助.代码如下:
Thanks for the help. Here is the code:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.brainPageController = new PageController();
// add items from the List<String> to the listBox
listGoals.ItemsSource = brainPageController.GetListGoals();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as String;
// a simple controller that adds a string to a List<string>
brainPageController.AddGoal(parameter);
}
private void addButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof (GoalsInfo));
}
// VARIABLES DECLARATION
private PageController brainPageController;
}
public sealed partial class GoalsInfo : WinGoalsWIP.Common.LayoutAwarePage
{
public GoalsInfo()
{
this.InitializeComponent();
this.brainPageController = new PageController();
}
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
}
protected override void SaveState(Dictionary<String, Object> pageState)
{
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
brainPageController.AddGoal(nameTextBox.Text);
this.Frame.Navigate(typeof(MainPage), nameTextBox.Text);
}
// VARIABLES DECLARATION
PageController brainPageController;
}
推荐答案
试试这个希望对你有帮助
Try this i hope it helps
快速入门:在页面之间导航
这篇关于如何在 Windows 8 样式应用程序中将对象从框架传递到另一个框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Windows 8 样式应用程序中将对象从框架传递到另一个框架
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01