最近我一直在尝试添加一个应该在某段时间内弹出的消息框(例如 应用启动次数 )。此消息框也可以永久隐藏而不会弹出。
答案 0 :(得分:0)
以下代码块可以放入任何现有的应用程序中,并有助于提供上述功能:
在.xaml页面中,
<phone:PhoneApplicationPage
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
xmlns:System="clr-namespace:System;assembly=mscorlib"
SupportedOrientations="Portrait" Orientation="Portrait"
Loaded="PhoneApplicationPage_Loaded"> **//Don't forget to add this code on your xaml page**
在.xaml.cs页面中,
public partial class MainPage : PhoneApplicationPage
{
private static bool PerformedRatingPromptCheck = false;
// Constructor
public MainPage()
{
InitializeComponent();
}
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (!PerformedRatingPromptCheck)
{
PerformedRatingPromptCheck = true;
int numAppLaunches = 0;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<int>("Rating_numAppLaunches", out numAppLaunches);
int numNextRatingPrompt = 0;
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue<int>("Rating_numNextRatingPrompt", out numNextRatingPrompt))
{
numNextRatingPrompt = 3;
}
if (numAppLaunches >= numNextRatingPrompt)
{
IsolatedStorageSettings.ApplicationSettings["Rating_numNextRatingPrompt"] = numNextRatingPrompt * 2;
NotificationBox.ShowAgain("Enjoying the app?",
"Would you like to rate this app now, support us?",
"Ask me later",
false,
Surpressed => { },
"Rating_MsgPrompt",
new NotificationBoxCommand("yes", () => { new MarketplaceReviewTask().Show(); }),
new NotificationBoxCommand("no", () => { }));
}
IsolatedStorageSettings.ApplicationSettings["Rating_numAppLaunches"] = numAppLaunches + 1;
}
}
来源 - Roybott Blog