Skip to content

Instantly share code, notes, and snippets.

@m-gagne
Last active December 22, 2015 18:39
Show Gist options
  • Save m-gagne/6514536 to your computer and use it in GitHub Desktop.
Save m-gagne/6514536 to your computer and use it in GitHub Desktop.
Windows 8 C# code sample that asks for a review of the app after 5 launches
// --------------------------------------------------
// Ask for a review after 5 starts of the Application
// --------------------------------------------------
// Variable to hold the number of time the app started
int startedCount = 0;
// Check if the variable was stored in the Roaming Settings before
if (Windows.Storage.ApplicationData.Current.RoamingSettings.Values.ContainsKey("startedCount"))
{
// If so, read it in the variable
startedCount = (int)Windows.Storage.ApplicationData.Current.RoamingSettings.Values["startedCount"];
}
// Increment the count by 1
startedCount++;
// And then save it in the Roaming Settings. Note that if the value pair was not
// created before, the method will create it automatically
Windows.Storage.ApplicationData.Current.RoamingSettings.Values["startedCount"] = startedCount;
// If the app was started 5 times
if (startedCount == 5)
{
// Create a MessageDialog requesting a review
var md = new Windows.UI.Popups.MessageDialog(
"Thank you for using [App Name] for a while now, would you like to review this app?",
"Please review my app");
// Build the 2 potential responses using the Commands collection
bool? reviewresult = null;
md.Commands.Add(new Windows.UI.Popups.UICommand(
"Yes",
new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = true)));
md.Commands.Add(new Windows.UI.Popups.UICommand(
"No",
new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = false)));
// Display the MessageBox asyncronously. ** Note that you may have to add the async
// keyword to the OnLaunched event definition above
await md.ShowAsync();
// If the user agrees
if (reviewresult == true)
{
// Find the FamilyName of the app package
string familyName = Package.Current.Id.FamilyName;
// Navigate to the store Review Page for the Application
await Windows.System.Launcher.LaunchUriAsync(new Uri(
string.Format("ms-windows-store:REVIEW?PFN={0}",
familyName)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment