如何在Windows 8样式应用程序中将对象从框架传递到另一个框架 [英] How to pass an object from a Frame to another Frame in a Windows 8 Style App

查看:50
本文介绍了如何在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和一个Button(让我们说 addButton ).

I have a MainWindow which contains a ListBox and a Button (lets say addButton).

当我单击按钮导航到新页面时,使用this.Frame.Navigate(typeof(addCustomerPage));说 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.创建MainWindow.

This is my current functionality: 1. MainWindow is created.

  1. 单击addButton

  1. Click addButton

AddCustomer页面已创建.MainWindow被破坏(问题).

AddCustomer page is created. MainWindow is destroyed(problem).

点击完成按钮

使用包含1个项目的ListBox创建MainWindow对象.

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样式应用程序中将对象从框架传递到另一个框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆