WP7中页面之间传值和保存恢复数据状态

本文演示了如何在Windows Phone应用中实现页面间的导航,并在导航前后保存和恢复TextBox控件的值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. MainPage.xaml,添加HyperlinkButton和TextBox控件

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="MainPage" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Height="97" Width="465" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <HyperlinkButton Content="NavigateToPage1" Height="30" 
                             HorizontalAlignment="Left" Margin="130,83,0,0" Name="hyperlinkButton1"
                             VerticalAlignment="Top" Width="200"
                             NavigateUri="/NavigatingBetweenPages;component/Views/Page1.xaml?id=3&" />
            <TextBox Height="72" HorizontalAlignment="Left" Margin="67,152,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="346" />
        </Grid>
    </Grid>

2. MainPage.cs,重写OnNavigatedFrom和OnNavigatedTo方法,保存MainPage中TextBox的值

using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace NavigatingBetweenPages
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
        // retain the value of the textbox
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            phoneAppService.State["myValue"] = textBox1.Text;
            base.OnNavigatedFrom(e);
        }
        // try to get the value which is retained
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            object someObject;
            if (phoneAppService.State.ContainsKey("myValue"))
            {
                if (phoneAppService.State.TryGetValue("myValue", out someObject))
                {
                    textBox1.Text = someObject.ToString();
                }
            }
            base.OnNavigatedTo(e);
        }
    }
}

3. 添加文件夹Views并添加Page1.xaml

4. Page1.xaml, 添加HyperlinkButton和TextBox控件

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page1.xaml" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Height="72" HorizontalAlignment="Left" Margin="88,26,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="271" />
            <HyperlinkButton Content="GoBackToMainPage" Height="30" HorizontalAlignment="Left" Margin="88,355,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="260" NavigateUri="/NavigatingBetweenPages;component/MainPage.xaml" />
        </Grid>
    </Grid>

5. Page1.cs, 利用NavigationContext.QueryString获取id的值

using System;
using System.Windows;
using Microsoft.Phone.Controls;

namespace NavigatingBetweenPages.Views
{
    public partial class Page1 : PhoneApplicationPage
    {
        public Page1()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            // get the value passed by uri(eg. /NavigatingBetweenPages;component/Views/Page1.xaml?id=3)
            //this.textBlock1.Text = String.Format("Value:{0}", NavigationContext.QueryString["id"]);
            string id = "";
            if (NavigationContext.QueryString.TryGetValue("id",out id))
            {
                textBlock1.Text = String.Format("Value:{0}", id);
            }
        }
    }
}


资源下载链接为: https://pan.quark.cn/s/d37d4dbee12c A:计算机视觉,作为人工智能领域的关键分支,致力于赋予计算机系统 “看懂” 世界的能力,从图像、视频等视觉数据中提取有用信息并据此决策。 其发展历程颇为漫长。早期图像处理技术为其奠基,后续逐步探索三维信息提取,与人工智能结合,又经历数学理论深化、机器学习兴起,直至当下深度学习引领浪潮。如今,图像生成合成技术不断发展,让计算机视觉更深入人们的日常生活。 计算机视觉综合了图像处理、机器学习、模式识别深度学习等技术。深度学习兴起后,卷积神经网络成为核心工具,能自动提炼复杂图像特征。它的工作流程,首先是图像获取,用相机等设备捕获视觉信息并数字化;接着进行预处理,通过滤波、去噪等操作提升图像质量;然后进入关键的特征提取描述环节,提炼图像关键信息;之后利用这些信息训练模型,学习视觉模式规律;最终用于模式识别、分类、对象检测等实际应用。 在实际应用中,计算机视觉用途极为广泛。在安防领域,能进行人脸识别、目标跟踪,保障公共安全;在自动驾驶领域,帮助车辆识别道路、行人、交通标志,实现安全行驶;在医疗领域,辅助医生分析医学影像,进行疾病诊断;在工业领域,用于产品质量检测、机器人操作引导等。 不过,计算机视觉发展也面临挑战。比如图像生成技术带来深度伪造风险,虚假图像视频可能误导大众、扰乱秩序。为此,各界积极研究检测技术,以应对这一问题。随着技术持续进步,计算机视觉有望在更多领域发挥更大作用,进一步改变人们的生活工作方式 。
内容概要:该论文探讨了光纤通信中光脉冲输性能的数仿真方法,重点研究了光脉冲在光纤中输时受到色散、损耗非线性效应的影响。文章采用分步傅里叶方法求解非线性薛定谔方程(NLSE),并对高斯脉冲、超高斯脉冲双曲正割脉冲三种常见光脉冲的输演化进行了仿真分析。结果显示,双曲正割脉冲在相同的输条件下具有最佳的抗色散非线性能力。此外,论文还通过改变群速度色散(GVD)非线性系数等参数,进一步分析了不同条件对光脉冲输性能的影响,并提出了脉冲选择策略系统设计建议。最后,通过性能评估指标对三种脉冲的输性能进行了量化分析,验证了分步傅里叶方法的有效性,并为光纤通信系统的优化设计提供了指导。 适合人群:从事光纤通信领域研究的技术人员、研究生以及对光脉冲输感兴趣的科研人员。 使用场景及目标:①理解光脉冲在光纤中输时所受的色散、损耗非线性效应的影响;②掌握分步傅里叶方法求解非线性薛定谔方程的具体步骤;③评估不同脉冲形状在光纤中的输性能,选择合适的脉冲类型优化系统参数;④为实际工程应用提供理论依据技术支持。 其他说明:论文不仅提供了详细的仿真代码结果分析,还通过扩展仿真展示了不同参数对光脉冲输性能的影响,有助于读者更全面地理解光脉冲输的物理机制工程应用前景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值