[英]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.