如何在 windows phone 8 的 Web 视图中根据月份的日期和时间显示不同的 html 页面:
How to Display different html pages according to date and time of the month in a webview in windows phone 8:
我的应用程序中有 366 html 个页面,每个 html 页面代表一年中的某一天,我想在我的应用程序中本地查看下面的代码只能查看单个 [=21] =] 页面,但我想要的是根据网络视图中的月份日期每天显示不同的 html 页面,即如果用户在 2016 年 2 月 3 日打开应用程序,应用程序应该打开 devotion62.html 这是一年中的第 62 天
这是我下面的代码
XAML
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser HorizontalAlignment="Left" Margin="20,50,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="500" Width="430" />
</Grid>
XAML.CS
public partial class MainPage : PhoneApplicationPage
{
private List<string> htmls;
private int CurrentIndex = 0;
private int TotalCount = 0;
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
htmls = new List<string>() { "/Bible/devotion60.html", "/Bible/devotion61.html", "/Bible/devotion62.html", "/Bible/devotion63.html" };//List of string will contain all the 366 html files path
TotalCount = htmls.Count;
if (TotalCount != 0)
{
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
}
private void Previous_Click(object sender, EventArgs e)
{
if (CurrentIndex != 0)
{
CurrentIndex--;
}
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
private void Next_Click(object sender, EventArgs e)
{
if (CurrentIndex != TotalCount - 1)
{
CurrentIndex++;
}
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
在您的 MainPage_Loaded
方法中添加以下代码。
CurrentIndex = DateTime.Now.DayOfYear;
我的应用程序中有 366 html 个页面,每个 html 页面代表一年中的某一天,我想在我的应用程序中本地查看下面的代码只能查看单个 [=21] =] 页面,但我想要的是根据网络视图中的月份日期每天显示不同的 html 页面,即如果用户在 2016 年 2 月 3 日打开应用程序,应用程序应该打开 devotion62.html 这是一年中的第 62 天 这是我下面的代码 XAML
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser HorizontalAlignment="Left" Margin="20,50,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="500" Width="430" />
</Grid>
XAML.CS
public partial class MainPage : PhoneApplicationPage
{
private List<string> htmls;
private int CurrentIndex = 0;
private int TotalCount = 0;
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
htmls = new List<string>() { "/Bible/devotion60.html", "/Bible/devotion61.html", "/Bible/devotion62.html", "/Bible/devotion63.html" };//List of string will contain all the 366 html files path
TotalCount = htmls.Count;
if (TotalCount != 0)
{
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
}
private void Previous_Click(object sender, EventArgs e)
{
if (CurrentIndex != 0)
{
CurrentIndex--;
}
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
private void Next_Click(object sender, EventArgs e)
{
if (CurrentIndex != TotalCount - 1)
{
CurrentIndex++;
}
webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
}
在您的 MainPage_Loaded
方法中添加以下代码。
CurrentIndex = DateTime.Now.DayOfYear;