简体   繁体   English

如何分配日期,在Windows Phone 8.1 C#中从上一页或窗体导航到日期选择器

[英]How to assign date,which is navigated from previous page or form to date picker in Windows Phone 8.1 C#

I want to assign a date,which date is navigated from another page/form to date picker in my current page. 我想分配一个日期,该日期从另一个页面/表单导航到当前页面中的日期选择器。 When I looked at internet I got the answer like. 当我看互联网时,我得到了类似的答案。

datepicker1.value = DateTime.Today; datepicker1.value = DateTime.Today;

But I am not getting datepicker. 但是我没有日期选择器。 value

I'm using Visual Studio 2013, and developing apps for Windows Phone 8.1. 我正在使用Visual Studio 2013,并为Windows Phone 8.1开发应用程序。

I am retrieving date from database in one form*(consider as first page) and sending to another form(secondary page). 我正在从数据库中以一种形式*(视为第一页)检索日期,并发送到另一种形式(第二页)。 In secondary page I need to display date in secondary page, which is coming from first page. 在第二页中,我需要在第二页中显示日期,该日期来自第一页。

You can use like this in your SecondPage 您可以在SecondPage中这样使用

var date= FirstPage.datepicker1.value

I am assuming that FirstPage is the namespace of the Page from where you want assign the value. 我假设FirstPage是您要从中分配值的Page的命名空间。 namespace SomeThing { class Program { public partial class SecondPage: PhoneApplicationPage { var date= FirstPage.datepicker1.value } } }

EDIT Ok I got your point. 编辑好的,我明白了。 You can set the datePicker value in **OnNavigatedTo ** function. 您可以在** OnNavigatedTo **函数中设置datePicker值。 And in the backend 在后端

protected override void OnNavigatedTo(NavigationEventArgs e)

{ {

    datePicker1.Date = DateTimeOffset.Now;
    datePicker1.MinYear = DateTimeOffset.Now;

} }

You have to pass the Date as a parameter to the second page. 您必须将日期作为参数传递给第二页。 Consider date is the parameter, Now in First page you can write 考虑日期为参数,现在在首页中您可以编写

protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        PhoneApplicationService.Current.State["Text"] = date;
    }

And in your Second Page you have to receive the date and assign it to datePicker1. 在第二页中,您必须接收日期并将其分配给datePicker1。

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    datePicker1.Date=(DateTime)PhoneApplicationService.Current.State["Text"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#Windows Form Datetime Picker工具从sqlserver中选择日期 - Select date to date from sqlserver using c# windows form datetime picker tools Windows Phone 8.1无法识别导航到的页面 - Windows Phone 8.1 Unable to Recognize the Page Being Navigated to 如何在WinRT-apps(Javascript,C#)中区分Windows Phone 8.1与Windows 8.1? - How to distinguish Windows Phone 8.1 from Windows 8.1 in WinRT-apps (Javascript, C#)? Windows Phone:日期选择器和按钮 - Windows phone: date picker and button 如何使用wpf在C#中使用sqlitedatareader对象在日期选择器上分配和显示日期值 - How to assign and display date value on date picker using sqlitedatareader object in C# using wpf 在Windows Phone 8.1(C#)中刷新页面或导航到同一页面 - Refresh a page or navigate to same page in windows phone 8.1 (c#) 识别Windows Phone 8.1中从哪个页面进入此页面 - Identify from which page come to this page in windows phone 8.1 从C#项目页面导航到Javascript项目页面Windows Phone 8.1 - Navigate from a C# Project Page to Javascript Project Page Windows Phone 8.1 从db(sqlite)检索日期并将其发布到Windows Phone 8.1中的listview中 - Retrive date from db(sqlite) and post it in listview in windows phone 8.1 为Windows Forms C#设置日期时间选择器的最小日期 - Setting Minimum Date for Date Time Picker for Windows Forms C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM