diff --git a/Samples/Accelerometer/README.md b/Samples/Accelerometer/README.md
index e6d0438927..848c9a9117 100644
--- a/Samples/Accelerometer/README.md
+++ b/Samples/Accelerometer/README.md
@@ -37,7 +37,8 @@ When you choose the **Enable** button for the **Data Events** option, the app be
When you choose the **Enable** button for the **Shake Events** option, the app displays the cumulative number of shake events each time an event occurs. (The app first increments the event count and then renders the most recent value.)
-Note that shake events are not supported in Windows 10 build 10240, so the Shaken event will never be raised, but the sample demonstrates how to handle the event when support for shake is added.
+Note that support for the Shaken event is dependent upon hardware and driver support.
+In practice, very few accelerometers support the Shaken event.
### Poll Accelerometer Readings
diff --git a/Samples/Accelerometer/js/html/scenario2_ShakeEvents.html b/Samples/Accelerometer/js/html/scenario2_ShakeEvents.html
index 209ebd3feb..1e8d4107c6 100644
--- a/Samples/Accelerometer/js/html/scenario2_ShakeEvents.html
+++ b/Samples/Accelerometer/js/html/scenario2_ShakeEvents.html
@@ -13,7 +13,10 @@
Description:
Shake events
-
Registers an event listener for accelerometer shake events and displays the cumulative count of shake events.
+
+ Registers an event listener for accelerometer shake events and displays the cumulative count of shake events.
+ Note that not all accelerometers report shake events.
+
diff --git a/Samples/Accelerometer/shared/Scenario2_ShakeEvents.xaml b/Samples/Accelerometer/shared/Scenario2_ShakeEvents.xaml
index 7274748100..55464f1bc1 100644
--- a/Samples/Accelerometer/shared/Scenario2_ShakeEvents.xaml
+++ b/Samples/Accelerometer/shared/Scenario2_ShakeEvents.xaml
@@ -22,7 +22,10 @@
-
+
+ Registers an event listener for accelerometer shake events and displays the cumulative count of shake events.
+ Note that not all accelerometers report shake events.
+
diff --git a/Samples/Altimeter/cpp/SampleConfiguration.cpp b/Samples/Altimeter/cpp/SampleConfiguration.cpp
index 2b5346d8f4..53cdd10800 100644
--- a/Samples/Altimeter/cpp/SampleConfiguration.cpp
+++ b/Samples/Altimeter/cpp/SampleConfiguration.cpp
@@ -15,8 +15,59 @@
using namespace SDKTemplate;
-Platform::Array^ MainPage::scenariosInner = ref new Platform::Array
+using namespace Concurrency;
+using namespace Platform;
+using namespace Windows::Devices::Enumeration;
+using namespace Windows::Devices::Sensors;
+using namespace Windows::Foundation::Metadata;
+
+Array^ MainPage::scenariosInner = ref new Array
{
{ "Data Events", "SDKTemplate.Scenario1_DataEvents" },
{ "Polling", "SDKTemplate.Scenario2_Polling" }
};
+
+// This works around an issue in the Anniversary Update (1607) in which
+// Altimeter::GetDefault() returns a nonfunctional altimeter if the
+// system has no altimeter. This issue does not exist in other versions
+// of Windows 10, but the workaround is harmless to use even on versions
+// which do not have this problem. The workaround returns the default
+// altimeter only after we confirm that the system has a working altimeter.
+
+task MainPage::GetDefaultAltimeterAsync()
+{
+ // Run this task only once, and cache the result.
+ static task altimeterTask = []()
+ {
+ // This workaround is needed only on the Anniversary Update (universal contract 3).
+ if (!ApiInformation::IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3) ||
+ ApiInformation::IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
+ {
+ // The current system does not require the workaround.
+ return task_from_result(Altimeter::GetDefault());
+ }
+
+ String^ deviceSelector =
+ // Find all interface classes for altimeter sensors
+ L"System.Devices.InterfaceClassGuid:=\"{0E903829-FF8A-4A93-97DF-3DCBDE402288}\""
+ // ... that are present on the system
+ L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True";
+
+ DeviceWatcher^ watcher = DeviceInformation::CreateWatcher(deviceSelector);
+ task_completion_event tce;
+ watcher->Added += ref new Windows::Foundation::TypedEventHandler(
+ [tce](DeviceWatcher^, DeviceInformation^) { tce.set(Altimeter::GetDefault()); });
+ watcher->EnumerationCompleted += ref new Windows::Foundation::TypedEventHandler(
+ [tce](DeviceWatcher^, Object^) { tce.set(nullptr); });
+ watcher->Start();
+
+ return task(tce).then([watcher](task previousTask)
+ {
+ // No matter what happens, make sure we stop the watcher.
+ watcher->Stop();
+ return previousTask;
+ });
+ }();
+
+ return altimeterTask;
+}
diff --git a/Samples/Altimeter/cpp/SampleConfiguration.h b/Samples/Altimeter/cpp/SampleConfiguration.h
index 6b7a7cf0db..3019f9b7ba 100644
--- a/Samples/Altimeter/cpp/SampleConfiguration.h
+++ b/Samples/Altimeter/cpp/SampleConfiguration.h
@@ -35,6 +35,8 @@ namespace SDKTemplate
}
}
+ static Concurrency::task GetDefaultAltimeterAsync();
+
private:
static Platform::Array^ scenariosInner;
};
diff --git a/Samples/Altimeter/cpp/Scenario1_DataEvents.xaml.cpp b/Samples/Altimeter/cpp/Scenario1_DataEvents.xaml.cpp
index 6363dea92c..17a97c8a31 100644
--- a/Samples/Altimeter/cpp/Scenario1_DataEvents.xaml.cpp
+++ b/Samples/Altimeter/cpp/Scenario1_DataEvents.xaml.cpp
@@ -27,22 +27,11 @@ using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
+using namespace Concurrency;
+
Scenario1_DataEvents::Scenario1_DataEvents() : rootPage(MainPage::Current), desiredReportIntervalMs(0)
{
InitializeComponent();
-
- sensor = Altimeter::GetDefault();
- if (nullptr != sensor)
- {
- // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
- // This value will be used later to activate the sensor.
- uint32 minReportIntervalMs = sensor->MinimumReportInterval;
- desiredReportIntervalMs = minReportIntervalMs > 1000 ? minReportIntervalMs : 1000;
- }
- else
- {
- rootPage->NotifyUser("No altimeter found", NotifyType::ErrorMessage);
- }
}
///
@@ -124,21 +113,29 @@ void Scenario1_DataEvents::ReadingChanged(Altimeter^ sender, AltimeterReadingCha
void Scenario1_DataEvents::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
- if (nullptr != sensor)
+ ScenarioEnableButton->IsEnabled = false;
+ MainPage::GetDefaultAltimeterAsync().then([this](Altimeter^ result)
{
- // Establish the report interval
- sensor->ReportInterval = desiredReportIntervalMs;
+ sensor = result;
+ if (nullptr != sensor)
+ {
+ // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
+ uint32 minReportIntervalMs = sensor->MinimumReportInterval;
+ desiredReportIntervalMs = minReportIntervalMs > 1000 ? minReportIntervalMs : 1000;
+ sensor->ReportInterval = desiredReportIntervalMs;
- visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged));
- readingToken = sensor->ReadingChanged::add(ref new TypedEventHandler(this, &Scenario1_DataEvents::ReadingChanged));
+ visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged));
+ readingToken = sensor->ReadingChanged::add(ref new TypedEventHandler(this, &Scenario1_DataEvents::ReadingChanged));
- ScenarioEnableButton->IsEnabled = false;
- ScenarioDisableButton->IsEnabled = true;
- }
- else
- {
- rootPage->NotifyUser("No Altimeter found", NotifyType::ErrorMessage);
- }
+ ScenarioEnableButton->IsEnabled = false;
+ ScenarioDisableButton->IsEnabled = true;
+ }
+ else
+ {
+ ScenarioEnableButton->IsEnabled = true;
+ rootPage->NotifyUser("No Altimeter found", NotifyType::ErrorMessage);
+ }
+ }, task_continuation_context::get_current_winrt_context());
}
void Scenario1_DataEvents::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
diff --git a/Samples/Altimeter/cpp/Scenario2_Polling.xaml.cpp b/Samples/Altimeter/cpp/Scenario2_Polling.xaml.cpp
index 11e8ef9d50..ecdc0b17d7 100644
--- a/Samples/Altimeter/cpp/Scenario2_Polling.xaml.cpp
+++ b/Samples/Altimeter/cpp/Scenario2_Polling.xaml.cpp
@@ -19,6 +19,7 @@
using namespace SDKTemplate;
+using namespace Concurrency;
using namespace Platform;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
@@ -30,26 +31,24 @@ using namespace Windows::UI::Xaml::Navigation;
Scenario2_Polling::Scenario2_Polling() : rootPage(MainPage::Current)
{
InitializeComponent();
-
- sensor = Altimeter::GetDefault();
- if (nullptr == sensor)
- {
- rootPage->NotifyUser("No altimeter found", NotifyType::ErrorMessage);
- }
}
void Scenario2_Polling::ScenarioGetData(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
- if (nullptr != sensor)
+ MainPage::GetDefaultAltimeterAsync().then([this](Altimeter^ result)
{
- AltimeterReading^ reading = sensor->GetCurrentReading();
- if (nullptr != reading)
+ sensor = result;
+ if (nullptr != sensor)
{
- ScenarioOutput_M->Text = reading->AltitudeChangeInMeters.ToString();
+ AltimeterReading^ reading = sensor->GetCurrentReading();
+ if (nullptr != reading)
+ {
+ ScenarioOutput_M->Text = reading->AltitudeChangeInMeters.ToString();
+ }
}
- }
- else
- {
- rootPage->NotifyUser("No altimeter found", NotifyType::ErrorMessage);
- }
+ else
+ {
+ rootPage->NotifyUser("No altimeter found", NotifyType::ErrorMessage);
+ }
+ }, task_continuation_context::get_current_winrt_context());
}
diff --git a/Samples/Altimeter/cpp/Scenario2_Polling.xaml.h b/Samples/Altimeter/cpp/Scenario2_Polling.xaml.h
index 4f1ebc8885..26d69f4933 100644
--- a/Samples/Altimeter/cpp/Scenario2_Polling.xaml.h
+++ b/Samples/Altimeter/cpp/Scenario2_Polling.xaml.h
@@ -35,6 +35,7 @@ namespace SDKTemplate
SDKTemplate::MainPage^ rootPage;
Windows::UI::Core::CoreDispatcher^ dispatcher;
Windows::Devices::Sensors::Altimeter^ sensor;
+
void ScenarioGetData(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}
\ No newline at end of file
diff --git a/Samples/Altimeter/cs/SampleConfiguration.cs b/Samples/Altimeter/cs/SampleConfiguration.cs
index 1c096c8b60..b49c80e7cb 100644
--- a/Samples/Altimeter/cs/SampleConfiguration.cs
+++ b/Samples/Altimeter/cs/SampleConfiguration.cs
@@ -11,6 +11,9 @@
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Windows.Devices.Sensors;
+using Windows.Foundation.Metadata;
using Windows.UI.Xaml.Controls;
namespace SDKTemplate
@@ -24,8 +27,53 @@ public partial class MainPage : Page
new Scenario() { Title = "Data Events", ClassType = typeof(Scenario1_DataEvents) },
new Scenario() { Title = "Polling", ClassType = typeof(Scenario2_Polling) }
};
+
+ // This works around an issue in the Anniversary Update (1607) in which
+ // Altimeter.GetDefault() returns a nonfunctional altimeter if the
+ // system has no altimeter. This issue does not exist in other versions
+ // of Windows 10, but the workaround is harmless to use even on versions
+ // which do not have this problem. The workaround returns the default
+ // altimeter only after we confirm that the system has a working altimeter.
+
+ private static async Task GetDefaultAltimeterWorkerAsync()
+ {
+ // This workaround is needed only on the Anniversary Update (universal contract 3).
+ if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3) ||
+ ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
+ {
+ // The current system does not require the workaround.
+ return Altimeter.GetDefault();
+ }
+
+ var tcs = new TaskCompletionSource();
+
+ string deviceSelector =
+ // Find all interface classes for altimeter sensors
+ "System.Devices.InterfaceClassGuid:=\"{0E903829-FF8A-4A93-97DF-3DCBDE402288}\"" +
+ // ... that are present on the system
+ " AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True";
+
+ var watcher = Windows.Devices.Enumeration.DeviceInformation.CreateWatcher(deviceSelector);
+
+ watcher.Added += (s, e) => tcs.TrySetResult(Altimeter.GetDefault());
+ watcher.EnumerationCompleted += (s, e) => tcs.TrySetResult(null);
+ watcher.Start();
+ Altimeter altimeter = await tcs.Task;
+ watcher.Stop();
+ return altimeter;
+ }
+
+ // Run this task only once, and cache the result.
+ private static Lazy> defaultAltimeterLazy =
+ new Lazy>(GetDefaultAltimeterWorkerAsync, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
+
+ public static Task GetDefaultAltimeterAsync()
+ {
+ return defaultAltimeterLazy.Value;
+ }
}
+
public class Scenario
{
public string Title { get; set; }
diff --git a/Samples/Altimeter/cs/Scenario1_DataEvents.xaml.cs b/Samples/Altimeter/cs/Scenario1_DataEvents.xaml.cs
index fb5daffd18..58dfac3b4e 100644
--- a/Samples/Altimeter/cs/Scenario1_DataEvents.xaml.cs
+++ b/Samples/Altimeter/cs/Scenario1_DataEvents.xaml.cs
@@ -32,19 +32,6 @@ public sealed partial class Scenario1_DataEvents : Page
public Scenario1_DataEvents()
{
this.InitializeComponent();
-
- sensor = Altimeter.GetDefault();
- if (null != sensor)
- {
- // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
- // This value will be used later to activate the sensor.
- uint minReportIntervalMs = sensor.MinimumReportInterval;
- desiredReportIntervalMs = minReportIntervalMs > 1000 ? minReportIntervalMs : 1000;
- }
- else
- {
- rootPage.NotifyUser("No altimeter found", NotifyType.ErrorMessage);
- }
}
///
@@ -124,11 +111,15 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
///
///
///
- private void ScenarioEnable(object sender, RoutedEventArgs e)
+ private async void ScenarioEnable(object sender, RoutedEventArgs e)
{
+ ScenarioEnableButton.IsEnabled = false;
+ sensor = await MainPage.GetDefaultAltimeterAsync();
if (null != sensor)
{
- // Establish the report interval
+ // Set a report interval that is both suitable for the purposes of the app and supported by the sensor.
+ uint minReportIntervalMs = sensor.MinimumReportInterval;
+ desiredReportIntervalMs = minReportIntervalMs > 1000 ? minReportIntervalMs : 1000;
sensor.ReportInterval = desiredReportIntervalMs;
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
@@ -139,6 +130,7 @@ private void ScenarioEnable(object sender, RoutedEventArgs e)
}
else
{
+ ScenarioEnableButton.IsEnabled = true;
rootPage.NotifyUser("No altimeter found", NotifyType.ErrorMessage);
}
}
diff --git a/Samples/Altimeter/cs/Scenario2_Polling.xaml.cs b/Samples/Altimeter/cs/Scenario2_Polling.xaml.cs
index f36410a37f..d1cd0e5ecc 100644
--- a/Samples/Altimeter/cs/Scenario2_Polling.xaml.cs
+++ b/Samples/Altimeter/cs/Scenario2_Polling.xaml.cs
@@ -31,12 +31,6 @@ public sealed partial class Scenario2_Polling : Page
public Scenario2_Polling()
{
this.InitializeComponent();
-
- sensor = Altimeter.GetDefault();
- if (null == sensor)
- {
- rootPage.NotifyUser("No altimeter found", NotifyType.ErrorMessage);
- }
}
///
@@ -44,8 +38,9 @@ public Scenario2_Polling()
///
///
///
- private void ScenarioGetData(object sender, RoutedEventArgs e)
+ private async void ScenarioGetData(object sender, RoutedEventArgs e)
{
+ sensor = await MainPage.GetDefaultAltimeterAsync();
if (null != sensor)
{
AltimeterReading reading = sensor.GetCurrentReading();
diff --git a/Samples/Altimeter/js/js/sample-configuration.js b/Samples/Altimeter/js/js/sample-configuration.js
index 22a7baf8c8..098f51337e 100644
--- a/Samples/Altimeter/js/js/sample-configuration.js
+++ b/Samples/Altimeter/js/js/sample-configuration.js
@@ -10,8 +10,48 @@
{ url: "/html/scenario2_Polling.html", title: "Polling" }
];
+ // This works around an issue in the Anniversary Update (1607) in which
+ // Altimeter.getDefault() returns a nonfunctional altimeter if the
+ // system has no altimeter. This issue does not exist in other versions
+ // of Windows 10, but the workaround is harmless to use even on versions
+ // which do not have this problem. The workaround returns the default
+ // altimeter only after we confirm that the system has a working altimeter.
+
+ var altimeterPromise;
+
+ function getDefaultAltimeterAsync() {
+ var Altimeter = Windows.Devices.Sensors.Altimeter;
+ var ApiInformation = Windows.Foundation.Metadata.ApiInformation;
+
+ // Create the promise only once, and cache the result.
+ if (!altimeterPromise) {
+ // This workaround is needed only on the Anniversary Update (universal contract 3).
+ if (!ApiInformation.isApiContractPresent("Windows.Foundation.UniversalApiContract", 3) ||
+ ApiInformation.isApiContractPresent("Windows.Foundation.UniversalApiContract", 4)) {
+ // The current system does not require the workaround.
+ altimeterPromise = WinJS.Promise.wrap(Altimeter.getDefault());
+ } else {
+ var deviceSelector =
+ // Find all interface classes for altimeter sensors
+ "System.Devices.InterfaceClassGuid:=\"{0E903829-FF8A-4A93-97DF-3DCBDE402288}\"" +
+ // ... that are present on the system
+ " AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True";
+
+ var watcher = Windows.Devices.Enumeration.DeviceInformation.createWatcher(deviceSelector, null);
+ altimeterPromise = new WinJS.Promise(function init(c) {
+ watcher.addEventListener("added", function added(s) { c(Altimeter.getDefault()); });
+ watcher.addEventListener("enumerationcompleted", function enumerationcompleted() { c(null); });
+ watcher.start();
+ });
+ altimeterPromise.done(function stopWatcher() { watcher.stop(); });
+ }
+ }
+ return altimeterPromise;
+ }
+
WinJS.Namespace.define("SdkSample", {
sampleTitle: sampleTitle,
- scenarios: new WinJS.Binding.List(scenarios)
+ scenarios: new WinJS.Binding.List(scenarios),
+ getDefaultAltimeterAsync: getDefaultAltimeterAsync
});
})();
\ No newline at end of file
diff --git a/Samples/Altimeter/js/js/scenario1_DataEvents.js b/Samples/Altimeter/js/js/scenario1_DataEvents.js
index 74ce350a1a..e977294771 100644
--- a/Samples/Altimeter/js/js/scenario1_DataEvents.js
+++ b/Samples/Altimeter/js/js/scenario1_DataEvents.js
@@ -11,20 +11,11 @@
document.getElementById("scenario1Revoke").addEventListener("click", disableReadingChangedScenario, false);
document.getElementById("scenario1Open").disabled = false;
document.getElementById("scenario1Revoke").disabled = true;
-
- altimeter = Windows.Devices.Sensors.Altimeter.getDefault();
- if (altimeter) {
- // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
- // This value will be used later to activate the sensor.
- var minReportIntervalMs = altimeter.minReportIntervalMs;
- desiredReportIntervalMs = minReportIntervalMs > 1000 ? minReportIntervalMs : 1000;
- } else {
- WinJS.log && WinJS.log("No altimeter found", "sample", "error");
- }
},
unload: function () {
if (document.getElementById("scenario1Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
+
altimeter.removeEventListener("readingchanged", onDataChanged);
// Return the report interval to its default to release resources while the sensor is not in use
@@ -59,17 +50,21 @@
}
function enableReadingChangedScenario() {
- if (altimeter) {
- // Set the desiredReportIntervalMs to enable the sensor events
- altimeter.desiredReportIntervalMs = desiredReportIntervalMs;
+ document.getElementById("scenario1Open").disabled = true;
+ SdkSample.getDefaultAltimeterAsync().then(function (result) {
+ altimeter = result;
+ if (altimeter) {
+ // Set the desiredReportIntervalMs to enable the sensor events
+ altimeter.desiredReportIntervalMs = desiredReportIntervalMs;
- document.addEventListener("visibilitychange", visibilityChangeHandler, false);
- altimeter.addEventListener("readingchanged", onDataChanged);
- document.getElementById("scenario1Open").disabled = true;
- document.getElementById("scenario1Revoke").disabled = false;
- } else {
- WinJS.log && WinJS.log("No altimeter found", "sample", "error");
- }
+ document.addEventListener("visibilitychange", visibilityChangeHandler, false);
+ altimeter.addEventListener("readingchanged", onDataChanged);
+ document.getElementById("scenario1Revoke").disabled = false;
+ } else {
+ document.getElementById("scenario1Open").disabled = false;
+ WinJS.log && WinJS.log("No altimeter found", "sample", "error");
+ }
+ });
}
function disableReadingChangedScenario() {
diff --git a/Samples/Altimeter/js/js/scenario2_Polling.js b/Samples/Altimeter/js/js/scenario2_Polling.js
index e8dc1d210e..68cea8a0d6 100644
--- a/Samples/Altimeter/js/js/scenario2_Polling.js
+++ b/Samples/Altimeter/js/js/scenario2_Polling.js
@@ -8,24 +8,20 @@
ready: function (element, options) {
document.getElementById("scenario2Open").addEventListener("click", enableGetReadingScenario, false);
document.getElementById("scenario2Open").disabled = false;
-
- altimeter = Windows.Devices.Sensors.Altimeter.getDefault();
- if (!altimeter) {
- WinJS.log && WinJS.log("No altimeter found", "sample", "error");
- }
- },
- unload: function () {
}
});
function enableGetReadingScenario() {
- if (altimeter) {
- var reading = altimeter.getCurrentReading();
- if (reading) {
- document.getElementById("readingOutputChangeInMeters").innerText = reading.altitudeChangeInMeters.toFixed(2);
+ SdkSample.getDefaultAltimeterAsync().then(function (result) {
+ altimeter = result;
+ if (altimeter) {
+ var reading = altimeter.getCurrentReading();
+ if (reading) {
+ document.getElementById("readingOutputChangeInMeters").innerText = reading.altitudeChangeInMeters.toFixed(2);
+ }
+ } else {
+ WinJS.log && WinJS.log("No altimeter found", "sample", "error");
}
- } else {
- WinJS.log && WinJS.log("No altimeter found", "sample", "error");
- }
+ });
}
})();
diff --git a/Samples/FilePickerContracts/cs/FileOpenPicker_PickAppFile.xaml.cs b/Samples/FilePickerContracts/cs/FileOpenPicker_PickAppFile.xaml.cs
index 8b03eab327..ac6f0e7908 100644
--- a/Samples/FilePickerContracts/cs/FileOpenPicker_PickAppFile.xaml.cs
+++ b/Samples/FilePickerContracts/cs/FileOpenPicker_PickAppFile.xaml.cs
@@ -27,7 +27,7 @@ namespace FilePickerContracts
///
public sealed partial class FileOpenPicker_PickAppFile : Page
{
- private const string id ="MyLocalFile";
+ private const string id = "MyLocalFile";
FileOpenPickerUI fileOpenPickerUI = FileOpenPickerPage.Current.fileOpenPickerUI;
CoreDispatcher dispatcher = Window.Current.Dispatcher;
@@ -44,29 +44,9 @@ private void UpdateButtonState(bool fileInBasket)
RemoveLocalFileButton.IsEnabled = fileInBasket;
}
- private async void OnFileRemoved(FileOpenPickerUI sender, FileRemovedEventArgs args)
- {
- // make sure that the item got removed matches the one we added.
- if (args.Id == id)
- {
- // The event handler may be invoked on a background thread, so use the Dispatcher to run the UI-related code on the UI thread.
- await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
- {
- OutputTextBlock.Text = Status.FileRemoved;
- UpdateButtonState(false);
- });
- }
- }
-
protected override void OnNavigatedTo(NavigationEventArgs e)
{
UpdateButtonState(fileOpenPickerUI.ContainsFile(id));
- fileOpenPickerUI.FileRemoved += new TypedEventHandler(OnFileRemoved);
- }
-
- protected override void OnNavigatedFrom(NavigationEventArgs e)
- {
- fileOpenPickerUI.FileRemoved -= new TypedEventHandler(OnFileRemoved);
}
private async void AddLocalFileButton_Click(object sender, RoutedEventArgs e)
diff --git a/Samples/FilePickerContracts/cs/FileOpenPicker_PickCachedFile.xaml.cs b/Samples/FilePickerContracts/cs/FileOpenPicker_PickCachedFile.xaml.cs
index 1b288b1b2c..04b56ce5f4 100644
--- a/Samples/FilePickerContracts/cs/FileOpenPicker_PickCachedFile.xaml.cs
+++ b/Samples/FilePickerContracts/cs/FileOpenPicker_PickCachedFile.xaml.cs
@@ -28,7 +28,7 @@ namespace FilePickerContracts
///
public sealed partial class FileOpenPicker_PickCachedFile : Page
{
- private const string id ="MyCachedFile";
+ private const string id = "MyCachedFile";
FileOpenPickerUI fileOpenPickerUI = FileOpenPickerPage.Current.fileOpenPickerUI;
CoreDispatcher dispatcher = Window.Current.Dispatcher;
@@ -45,29 +45,9 @@ private void UpdateButtonState(bool fileInBasket)
RemoveFileButton.IsEnabled = fileInBasket;
}
- private async void OnFileRemoved(FileOpenPickerUI sender, FileRemovedEventArgs args)
- {
- // make sure that the item got removed matches the one we added.
- if (args.Id == id)
- {
- // The event handler may be invoked on a background thread, so use the Dispatcher to run the UI-related code on the UI thread.
- await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
- {
- OutputTextBlock.Text = Status.FileRemoved;
- UpdateButtonState(false);
- });
- }
- }
-
protected override void OnNavigatedTo(NavigationEventArgs e)
{
UpdateButtonState(fileOpenPickerUI.ContainsFile(id));
- fileOpenPickerUI.FileRemoved += new TypedEventHandler(OnFileRemoved);
- }
-
- protected override void OnNavigatedFrom(NavigationEventArgs e)
- {
- fileOpenPickerUI.FileRemoved -= new TypedEventHandler(OnFileRemoved);
}
private async void AddFileButton_Click(object sender, RoutedEventArgs e)
diff --git a/Samples/FilePickerContracts/cs/FileOpenPicker_PickURLFile.xaml.cs b/Samples/FilePickerContracts/cs/FileOpenPicker_PickURLFile.xaml.cs
index 1911f3034c..47a417941f 100644
--- a/Samples/FilePickerContracts/cs/FileOpenPicker_PickURLFile.xaml.cs
+++ b/Samples/FilePickerContracts/cs/FileOpenPicker_PickURLFile.xaml.cs
@@ -44,29 +44,9 @@ private void UpdateButtonState(bool fileInBasket)
RemoveURLFileButton.IsEnabled = fileInBasket;
}
- private async void OnFileRemoved(FileOpenPickerUI sender, FileRemovedEventArgs args)
- {
- // make sure that the item got removed matches the one we added.
- if (args.Id == id)
- {
- // The event handler may be invoked on a background thread, so use the Dispatcher to run the UI-related code on the UI thread.
- await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
- {
- OutputTextBlock.Text = Status.FileRemoved;
- UpdateButtonState(false);
- });
- }
- }
-
protected override void OnNavigatedTo(NavigationEventArgs e)
{
UpdateButtonState(fileOpenPickerUI.ContainsFile(id));
- fileOpenPickerUI.FileRemoved += new TypedEventHandler(OnFileRemoved);
- }
-
- protected override void OnNavigatedFrom(NavigationEventArgs e)
- {
- fileOpenPickerUI.FileRemoved -= new TypedEventHandler(OnFileRemoved);
}
private async void AddUriFileButton_Click(object sender, RoutedEventArgs e)
diff --git a/Samples/FilePickerContracts/cs/FileSavePicker_SaveToCachedFile.xaml.cs b/Samples/FilePickerContracts/cs/FileSavePicker_SaveToCachedFile.xaml.cs
index 04baa3c334..967c2d90f4 100644
--- a/Samples/FilePickerContracts/cs/FileSavePicker_SaveToCachedFile.xaml.cs
+++ b/Samples/FilePickerContracts/cs/FileSavePicker_SaveToCachedFile.xaml.cs
@@ -76,7 +76,7 @@ private async Task RegisterBackgroundTaskAsync()
{
await BackgroundExecutionManager.RequestAccessAsync();
- string backgroundTaskName = "CachedFileUpdaterTask";
+ string backgroundTaskName = "FilePickerContractsTasks";
string backgroundTaskEntryPoint = typeof(FilePickerContractsTasks.UpdateFileTask).FullName;
// Do nothing if the task is already registered.
diff --git a/Samples/FilePickerContracts/cs/Package.appxmanifest b/Samples/FilePickerContracts/cs/Package.appxmanifest
index 70144925ab..a9791e65f8 100644
--- a/Samples/FilePickerContracts/cs/Package.appxmanifest
+++ b/Samples/FilePickerContracts/cs/Package.appxmanifest
@@ -39,7 +39,7 @@
-
+
diff --git a/Samples/SimpleInk/cpp/Scenario2.xaml.cpp b/Samples/SimpleInk/cpp/Scenario2.xaml.cpp
index 5ee688ba48..e54d78eb4d 100644
--- a/Samples/SimpleInk/cpp/Scenario2.xaml.cpp
+++ b/Samples/SimpleInk/cpp/Scenario2.xaml.cpp
@@ -42,7 +42,7 @@ InkDrawingAttributes^ CalligraphicPen::CreateInkDrawingAttributesCore(Brush^ bru
}
inkDrawingAttributes->Size = Size((float)strokeWidth, 2.0f * (float)strokeWidth);
- inkDrawingAttributes->PenTipTransform = make_float3x2_rotation((float)((M_PI * 45.0) / 180.0), float2::zero());
+ inkDrawingAttributes->PenTipTransform = make_float3x2_rotation((float)((M_PI * 45.0) / 180.0));
return inkDrawingAttributes;
}
diff --git a/Samples/SimpleInk/cpp/Scenario3.xaml.cpp b/Samples/SimpleInk/cpp/Scenario3.xaml.cpp
index bf9ed6ca88..2854ec7904 100644
--- a/Samples/SimpleInk/cpp/Scenario3.xaml.cpp
+++ b/Samples/SimpleInk/cpp/Scenario3.xaml.cpp
@@ -160,7 +160,7 @@ void Scenario3::OnPenTypeChanged(Object^ sender, RoutedEventArgs^ e)
// Set a 45 degree rotation on the pen tip
double radians = 45.0 * M_PI / 180.0;
- drawingAttributes->PenTipTransform = make_float3x2_rotation((float)radians, float2::zero());
+ drawingAttributes->PenTipTransform = make_float3x2_rotation((float)radians);
}
else if (value == "Pencil")
{
diff --git a/Samples/SimpleInk/cs/Scenario2.xaml.cs b/Samples/SimpleInk/cs/Scenario2.xaml.cs
index 40653a3abc..d09609819f 100644
--- a/Samples/SimpleInk/cs/Scenario2.xaml.cs
+++ b/Samples/SimpleInk/cs/Scenario2.xaml.cs
@@ -40,7 +40,7 @@ protected override InkDrawingAttributes CreateInkDrawingAttributesCore(Brush bru
}
inkDrawingAttributes.Size = new Size(strokeWidth, 2.0f * strokeWidth);
- inkDrawingAttributes.PenTipTransform = System.Numerics.Matrix3x2.CreateRotation(45.0f);
+ inkDrawingAttributes.PenTipTransform = System.Numerics.Matrix3x2.CreateRotation((float)(Math.PI * 45 / 180));
return inkDrawingAttributes;
}
diff --git a/Samples/XamlContextMenu/cpp/ContextMenu.sln b/Samples/XamlContextMenu/cpp/ContextMenu.sln
new file mode 100644
index 0000000000..d139d8ce93
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/ContextMenu.sln
@@ -0,0 +1,40 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.22823.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ContextMenu", "ContextMenu.vcxproj", "{F710B9FD-4E6B-42D7-A99A-6D48888D48B0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM = Debug|ARM
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM = Release|ARM
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|ARM.ActiveCfg = Debug|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|ARM.Build.0 = Debug|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|ARM.Deploy.0 = Debug|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x64.ActiveCfg = Debug|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x64.Build.0 = Debug|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x64.Deploy.0 = Debug|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x86.ActiveCfg = Debug|Win32
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x86.Build.0 = Debug|Win32
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Debug|x86.Deploy.0 = Debug|Win32
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|ARM.ActiveCfg = Release|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|ARM.Build.0 = Release|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|ARM.Deploy.0 = Release|ARM
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x64.ActiveCfg = Release|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x64.Build.0 = Release|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x64.Deploy.0 = Release|x64
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x86.ActiveCfg = Release|Win32
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x86.Build.0 = Release|Win32
+ {F710B9FD-4E6B-42D7-A99A-6D48888D48B0}.Release|x86.Deploy.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj b/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj
new file mode 100644
index 0000000000..01eb435c37
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj
@@ -0,0 +1,248 @@
+
+
+
+ {f710b9fd-4e6b-42d7-a99a-6d48888d48b0}
+ SDKTemplate
+ en-US
+ 14.0
+ true
+ Windows Store
+ 10.0
+ 10.0.14393.0
+ 10.0.14393.0
+ true
+
+
+
+
+ Debug
+ ARM
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ ARM
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ Application
+ true
+ v140
+
+
+ Application
+ true
+ v140
+
+
+ Application
+ true
+ v140
+
+
+ Application
+ false
+ true
+ v140
+ true
+
+
+ Application
+ false
+ true
+ v140
+ true
+
+
+ Application
+ false
+ true
+ v140
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath);..\..\..\SharedContent\cpp
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+
+
+ ..\..\..\SharedContent\xaml\App.xaml
+
+
+ ..\..\..\SharedContent\cpp\MainPage.xaml
+
+
+
+ ..\shared\Scenario1.xaml
+
+
+ ..\shared\Scenario2.xaml
+
+
+ ..\shared\Scenario3.xaml
+
+
+
+
+ Designer
+
+
+ Designer
+
+
+
+
+
+ Styles\Styles.xaml
+
+
+
+
+ Designer
+
+
+
+
+ ..\..\..\SharedContent\xaml\App.xaml
+
+
+ ..\..\..\SharedContent\cpp\MainPage.xaml
+
+
+ Create
+ Create
+ Create
+ Create
+ Create
+ Create
+
+
+
+ ..\shared\Scenario1.xaml
+
+
+ ..\shared\Scenario2.xaml
+
+
+ ..\shared\Scenario3.xaml
+
+
+
+
+ Assets\cliff.jpg
+
+
+ Assets\grapes.jpg
+
+
+ Assets\microsoft-sdk.png
+
+
+ Assets\rainier.jpg
+
+
+ Assets\smallTile-sdk.png
+
+
+ Assets\splash-sdk.png
+
+
+ Assets\squareTile-sdk.png
+
+
+ Assets\storeLogo-sdk.png
+
+
+ Assets\sunset.jpg
+
+
+ Assets\tile-sdk.png
+
+
+ Assets\treetops.jpg
+
+
+ Assets\valley.jpg
+
+
+ Assets\windows-sdk.png
+
+
+
+
+
+
diff --git a/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj.filters b/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj.filters
new file mode 100644
index 0000000000..5b687ca7d4
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/ContextMenu.vcxproj.filters
@@ -0,0 +1,86 @@
+
+
+
+
+ 80bfd669-aa83-4537-9611-027cffe0d8af
+ bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png
+
+
+ {c6978fb6-bc64-498d-97c8-f5b53997e54e}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Styles
+
+
+
+
+
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+
diff --git a/Samples/XamlContextMenu/cpp/Package.appxmanifest b/Samples/XamlContextMenu/cpp/Package.appxmanifest
new file mode 100644
index 0000000000..51582670a1
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Package.appxmanifest
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+ Xaml Context Menu C++ Sample
+ Microsoft Corporation
+ Assets\StoreLogo-sdk.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Samples/XamlContextMenu/cpp/SampleConfiguration.cpp b/Samples/XamlContextMenu/cpp/SampleConfiguration.cpp
new file mode 100644
index 0000000000..6cf6c69468
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/SampleConfiguration.cpp
@@ -0,0 +1,23 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "MainPage.xaml.h"
+#include "SampleConfiguration.h"
+
+using namespace SDKTemplate;
+
+Platform::Array^ MainPage::scenariosInner = ref new Platform::Array
+{
+ { "ContextFlyout on an element", "SDKTemplate.Scenario1" },
+ { "ContextFlyout in ListView", "SDKTemplate.Scenario2" },
+ { "ContextRequested event", "SDKTemplate.Scenario3" },
+};
diff --git a/Samples/XamlContextMenu/cpp/SampleConfiguration.h b/Samples/XamlContextMenu/cpp/SampleConfiguration.h
new file mode 100644
index 0000000000..d184e09fd8
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/SampleConfiguration.h
@@ -0,0 +1,47 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+#include "pch.h"
+
+namespace SDKTemplate
+{
+ value struct Scenario;
+
+ partial ref class MainPage
+ {
+ internal:
+ static property Platform::String^ FEATURE_NAME
+ {
+ Platform::String^ get()
+ {
+ return "Resize app view";
+ }
+ }
+
+ static property Platform::Array^ scenarios
+ {
+ Platform::Array^ get()
+ {
+ return scenariosInner;
+ }
+ }
+
+ private:
+ static Platform::Array^ scenariosInner;
+ };
+
+ public value struct Scenario
+ {
+ Platform::String^ Title;
+ Platform::String^ ClassName;
+ };
+}
diff --git a/Samples/XamlContextMenu/cpp/SampleDataModel.h b/Samples/XamlContextMenu/cpp/SampleDataModel.h
new file mode 100644
index 0000000000..0c44bf3bae
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/SampleDataModel.h
@@ -0,0 +1,47 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+
+namespace SDKTemplate
+{
+ public ref class SampleDataModel sealed
+ {
+ public:
+ property Platform::String^ Title {
+ Platform::String^ get() { return m_title; }
+ }
+ property Platform::String^ ImagePath {
+ Platform::String^ get() { return m_imagePath; }
+ }
+
+ SampleDataModel(Platform::String^ title, Platform::String^ imagePath)
+ : m_title(title), m_imagePath(imagePath)
+ {
+ }
+
+ static Windows::Foundation::Collections::IVector^ GetSampleData()
+ {
+ return ref new Platform::Collections::Vector{
+ ref new SampleDataModel("Cliff", "Assets/cliff.jpg"),
+ ref new SampleDataModel("Grapes", "Assets/grapes.jpg"),
+ ref new SampleDataModel("Rainier", "Assets/Rainier.jpg"),
+ ref new SampleDataModel("Sunset", "Assets/Sunset.jpg"),
+ ref new SampleDataModel("Treetops", "Assets/Treetops.jpg"),
+ ref new SampleDataModel("Valley", "Assets/Valley.jpg"),
+ };
+ }
+
+ private:
+ Platform::String^ m_title;
+ Platform::String^ m_imagePath;
+ };
+}
diff --git a/Samples/XamlContextMenu/cpp/Scenario1.xaml.cpp b/Samples/XamlContextMenu/cpp/Scenario1.xaml.cpp
new file mode 100644
index 0000000000..99f62efa03
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario1.xaml.cpp
@@ -0,0 +1,43 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+#include "pch.h"
+#include "Scenario1.xaml.h"
+
+using namespace SDKTemplate;
+
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::UI::Core;
+using namespace Windows::UI::ViewManagement;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+using namespace Windows::UI::Xaml::Input;
+
+Scenario1::Scenario1()
+{
+ InitializeComponent();
+}
+
+void Scenario1::OpenMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ rootPage->NotifyUser("Action: Open", NotifyType::StatusMessage);
+}
+
+void Scenario1::PrintMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ rootPage->NotifyUser("Action: Print", NotifyType::StatusMessage);
+}
+
+void Scenario1::DeleteMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ rootPage->NotifyUser("Action: Delete", NotifyType::StatusMessage);
+}
diff --git a/Samples/XamlContextMenu/cpp/Scenario1.xaml.h b/Samples/XamlContextMenu/cpp/Scenario1.xaml.h
new file mode 100644
index 0000000000..484dee5ef7
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario1.xaml.h
@@ -0,0 +1,32 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+
+#include "Scenario1.g.h"
+#include "MainPage.xaml.h"
+
+namespace SDKTemplate
+{
+ [Windows::Foundation::Metadata::WebHostHidden]
+ public ref class Scenario1 sealed
+ {
+ public:
+ Scenario1();
+
+ private:
+ MainPage^ rootPage = MainPage::Current;
+
+ void OpenMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void PrintMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void DeleteMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ };
+}
diff --git a/Samples/XamlContextMenu/cpp/Scenario2.xaml.cpp b/Samples/XamlContextMenu/cpp/Scenario2.xaml.cpp
new file mode 100644
index 0000000000..b78c545951
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario2.xaml.cpp
@@ -0,0 +1,55 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "Scenario2.xaml.h"
+
+using namespace SDKTemplate;
+
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+
+Scenario2::Scenario2()
+{
+ InitializeComponent();
+ AllItems = SampleDataModel::GetSampleData();
+}
+
+SampleDataModel^ Scenario2::GetDataModelForCurrentListViewFlyout()
+{
+ // Obtain the ListViewItem for which the user requested a context menu.
+ auto listViewItem = SharedFlyout->Target;
+
+ // Get the data model for the ListViewItem.
+ return safe_cast(ItemListView->ItemFromContainer(listViewItem));
+}
+
+void Scenario2::OpenMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Open", NotifyType::StatusMessage);
+}
+
+void Scenario2::PrintMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Print", NotifyType::StatusMessage);
+}
+
+void Scenario2::DeleteMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Delete", NotifyType::StatusMessage);
+}
+
diff --git a/Samples/XamlContextMenu/cpp/Scenario2.xaml.h b/Samples/XamlContextMenu/cpp/Scenario2.xaml.h
new file mode 100644
index 0000000000..a457672199
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario2.xaml.h
@@ -0,0 +1,36 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+
+#include "Scenario2.g.h"
+#include "MainPage.xaml.h"
+#include "SampleDataModel.h"
+
+namespace SDKTemplate
+{
+ [Windows::Foundation::Metadata::WebHostHidden]
+ public ref class Scenario2 sealed
+ {
+ public:
+ Scenario2();
+
+ property Windows::Foundation::Collections::IVector^ AllItems;
+
+ private:
+ MainPage^ rootPage = MainPage::Current;
+
+ SampleDataModel^ GetDataModelForCurrentListViewFlyout();
+ void OpenMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void PrintMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void DeleteMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ };
+}
diff --git a/Samples/XamlContextMenu/cpp/Scenario3.xaml.cpp b/Samples/XamlContextMenu/cpp/Scenario3.xaml.cpp
new file mode 100644
index 0000000000..c6a9ede022
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario3.xaml.cpp
@@ -0,0 +1,92 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "pch.h"
+#include "Scenario3.xaml.h"
+
+using namespace SDKTemplate;
+
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+using namespace Windows::UI::Xaml::Input;
+using namespace Windows::UI::Xaml::Media;
+
+Scenario3::Scenario3()
+{
+ InitializeComponent();
+ AllItems = SampleDataModel::GetSampleData();
+ sharedFlyout = safe_cast(Resources->Lookup("SampleContextMenu"));
+}
+
+void Scenario3::ListView_ContextRequested(UIElement^ sender, ContextRequestedEventArgs^ e)
+{
+ // Walk up the tree to find the ListViewItem.
+ // There may not be one if the click wasn't on an item.
+ auto requestedElement = safe_cast(e->OriginalSource);
+ while ((requestedElement != sender) && !dynamic_cast(requestedElement))
+ {
+ requestedElement = safe_cast(VisualTreeHelper::GetParent(requestedElement));
+ }
+ if (requestedElement != sender)
+ {
+ // The context menu request was indeed for a ListViewItem.
+ auto model = safe_cast(ItemListView->ItemFromContainer(requestedElement));
+ Point point;
+ if (e->TryGetPosition(requestedElement, &point))
+ {
+ rootPage->NotifyUser("Showing flyout for " + model->Title + " at " + point.X.ToString() + "," + point.Y.ToString(), NotifyType::StatusMessage);
+ sharedFlyout->ShowAt(requestedElement, point);
+ }
+ else
+ {
+ // Not invoked via pointer, so let XAML choose a default location.
+ rootPage->NotifyUser("Showing flyout for " + model->Title + " at default location", NotifyType::StatusMessage);
+ sharedFlyout->ShowAt(requestedElement);
+ }
+
+ e->Handled = true;
+ }
+}
+
+void Scenario3::ListView_ContextCanceled(UIElement^ sender, RoutedEventArgs^ e)
+{
+ sharedFlyout->Hide();
+}
+
+SampleDataModel^ Scenario3::GetDataModelForCurrentListViewFlyout()
+{
+ // Obtain the ListViewItem for which the user requested a context menu.
+ auto listViewItem = sharedFlyout->Target;
+
+ // Get the data model for the ListViewItem.
+ return safe_cast(ItemListView->ItemFromContainer(listViewItem));
+}
+
+void Scenario3::OpenMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Open", NotifyType::StatusMessage);
+}
+
+void Scenario3::PrintMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Print", NotifyType::StatusMessage);
+}
+
+void Scenario3::DeleteMenuItem_Click(Platform::Object^ sender, RoutedEventArgs^ e)
+{
+ SampleDataModel^ model = GetDataModelForCurrentListViewFlyout();
+ rootPage->NotifyUser("Item: " + model->Title + ", Action: Delete", NotifyType::StatusMessage);
+}
+
diff --git a/Samples/XamlContextMenu/cpp/Scenario3.xaml.h b/Samples/XamlContextMenu/cpp/Scenario3.xaml.h
new file mode 100644
index 0000000000..0f09fcbf05
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/Scenario3.xaml.h
@@ -0,0 +1,40 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#pragma once
+
+#include "Scenario3.g.h"
+#include "MainPage.xaml.h"
+#include "SampleDataModel.h"
+
+namespace SDKTemplate
+{
+ [Windows::Foundation::Metadata::WebHostHidden]
+ public ref class Scenario3 sealed
+ {
+ public:
+ Scenario3();
+
+ property Windows::Foundation::Collections::IVector^ AllItems;
+
+ private:
+ MainPage^ rootPage = MainPage::Current;
+ Windows::UI::Xaml::Controls::MenuFlyout^ sharedFlyout;
+
+ void ListView_ContextRequested(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::Input::ContextRequestedEventArgs^ e);
+ void ListView_ContextCanceled(Windows::UI::Xaml::UIElement^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ SampleDataModel^ GetDataModelForCurrentListViewFlyout();
+
+ void OpenMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void PrintMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void DeleteMenuItem_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ };
+}
diff --git a/Samples/XamlContextMenu/cpp/pch.cpp b/Samples/XamlContextMenu/cpp/pch.cpp
new file mode 100644
index 0000000000..ade821753a
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/pch.cpp
@@ -0,0 +1,5 @@
+//
+// Include the standard header and generate the precompiled header.
+//
+
+#include "pch.h"
diff --git a/Samples/XamlContextMenu/cpp/pch.h b/Samples/XamlContextMenu/cpp/pch.h
new file mode 100644
index 0000000000..1dcc72eba4
--- /dev/null
+++ b/Samples/XamlContextMenu/cpp/pch.h
@@ -0,0 +1,10 @@
+//
+// Header for standard system include files.
+//
+
+#pragma once
+
+#include
+#include
+
+#include "App.xaml.h"
diff --git a/Samples/XamlContextMenu/cs/ContextMenu.csproj b/Samples/XamlContextMenu/cs/ContextMenu.csproj
index 94b096400c..6c3bbcd5f2 100644
--- a/Samples/XamlContextMenu/cs/ContextMenu.csproj
+++ b/Samples/XamlContextMenu/cs/ContextMenu.csproj
@@ -7,12 +7,12 @@
{DC30CE66-DAEE-4CCF-BD02-8837FE918B6F}AppContainerExeProperties
- ContextMenuCS
- ContextMenuCS
+ SDKTemplate
+ ContextMenuen-USUAP10.0.14393.0
- 10.0.10240.0
+ 10.0.14393.014true512
@@ -95,7 +95,8 @@
App.xaml.cs
App.xaml
-
+
+ MainPage.xaml.cs
MainPage.xaml
@@ -106,6 +107,12 @@
Scenario1.xaml
+
+ Scenario2.xaml
+
+
+ Scenario3.xaml
+
@@ -118,11 +125,23 @@
MSBuild:CompileDesigner
-
+
+ MainPage.xaml
+ MSBuild:Compile
+ Designer
+
+
+ Scenario1.xaml
+ MSBuild:Compile
+ Designer
+
+
+ Scenario2.xaml
MSBuild:CompileDesigner
-
+
+ Scenario3.xaml
MSBuild:CompileDesigner
diff --git a/Samples/XamlContextMenu/cs/MainPage.xaml b/Samples/XamlContextMenu/cs/MainPage.xaml
deleted file mode 100644
index 9bf4a895a4..0000000000
--- a/Samples/XamlContextMenu/cs/MainPage.xaml
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Samples/XamlContextMenu/cs/MainPage.xaml.cs b/Samples/XamlContextMenu/cs/MainPage.xaml.cs
deleted file mode 100644
index 094053f013..0000000000
--- a/Samples/XamlContextMenu/cs/MainPage.xaml.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-//*********************************************************
-//
-// Copyright (c) Microsoft. All rights reserved.
-// This code is licensed under the MIT License (MIT).
-// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
-// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
-// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
-// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
-//
-//*********************************************************
-
-using System;
-using System.Collections.Generic;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Navigation;
-
-// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
-
-namespace SDKTemplate
-{
- ///
- /// An empty page that can be used on its own or navigated to within a Frame.
- ///
- public sealed partial class MainPage : Page
- {
- public static MainPage Current;
-
- public MainPage()
- {
- this.InitializeComponent();
-
- // This is a static public property that allows downstream pages to get a handle to the MainPage instance
- // in order to call methods that are in this class.
- Current = this;
- SampleTitle.Text = FEATURE_NAME;
- }
-
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- ScenarioControl.ItemsSource = scenarios;
- if (Window.Current.Bounds.Width < 640)
- {
- ScenarioControl.SelectedIndex = -1;
- }
- else
- {
- ScenarioControl.SelectedIndex = 0;
- }
- }
-
- ///
- /// Called whenever the user changes selection in the scenarios list. This method will navigate to the respective
- /// sample scenario page.
- ///
- ///
- ///
- private void ScenarioControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- // Clear the status block when navigating scenarios.
- NotifyUser(String.Empty, NotifyType.StatusMessage);
-
- ListBox scenarioListBox = sender as ListBox;
- Scenario s = scenarioListBox.SelectedItem as Scenario;
- if (s != null)
- {
- ScenarioFrame.Navigate(s.ClassType);
- if (Window.Current.Bounds.Width < 640)
- {
- Splitter.IsPaneOpen = false;
- StatusBorder.Visibility = Visibility.Collapsed;
- }
- }
- }
-
- public List Scenarios
- {
- get { return this.scenarios; }
- }
-
- ///
- /// Used to display messages to the user
- ///
- ///
- ///
- public void NotifyUser(string strMessage, NotifyType type)
- {
- switch (type)
- {
- case NotifyType.StatusMessage:
- StatusBorder.Background = new SolidColorBrush(Windows.UI.Colors.Green);
- break;
- case NotifyType.ErrorMessage:
- StatusBorder.Background = new SolidColorBrush(Windows.UI.Colors.Red);
- break;
- }
- StatusBlock.Text = strMessage;
-
- // Collapse the StatusBlock if it has no text to conserve real estate.
- StatusBorder.Visibility = (StatusBlock.Text != String.Empty) ? Visibility.Visible : Visibility.Collapsed;
- }
-
- async void Footer_Click(object sender, RoutedEventArgs e)
- {
- await Windows.System.Launcher.LaunchUriAsync(new Uri(((HyperlinkButton)sender).Tag.ToString()));
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Splitter.IsPaneOpen = (Splitter.IsPaneOpen == true) ? false : true;
- StatusBorder.Visibility = Visibility.Collapsed;
- }
- }
- public enum NotifyType
- {
- StatusMessage,
- ErrorMessage
- };
-
- public class ScenarioBindingConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, string language)
- {
- Scenario s = value as Scenario;
- return (MainPage.Current.Scenarios.IndexOf(s) + 1) + ") " + s.Title;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, string language)
- {
- return true;
- }
- }
-}
-
diff --git a/Samples/XamlContextMenu/cs/Package.appxmanifest b/Samples/XamlContextMenu/cs/Package.appxmanifest
index 2a180cdb90..c9931d4f6d 100644
--- a/Samples/XamlContextMenu/cs/Package.appxmanifest
+++ b/Samples/XamlContextMenu/cs/Package.appxmanifest
@@ -7,20 +7,20 @@
IgnorableNamespaces="uap mp">
- ContextMenuCS C# Sample
+ XAML Context Menu C# SampleMicrosoft CorporationAssets\StoreLogo-sdk.png
-
+
@@ -30,10 +30,10 @@
+ EntryPoint="ContextMenu.App">
@@ -46,8 +46,4 @@
-
-
-
-
-
\ No newline at end of file
+
diff --git a/Samples/XamlContextMenu/cs/SampleConfiguration.cs b/Samples/XamlContextMenu/cs/SampleConfiguration.cs
index bdbd28363d..3444a10aa7 100644
--- a/Samples/XamlContextMenu/cs/SampleConfiguration.cs
+++ b/Samples/XamlContextMenu/cs/SampleConfiguration.cs
@@ -12,17 +12,18 @@
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
-using ContextMenuCS;
namespace SDKTemplate
{
public partial class MainPage : Page
{
- public const string FEATURE_NAME = "ContextMenuCS";
+ public const string FEATURE_NAME = "XAML Context Menu";
List scenarios = new List
{
- new Scenario() { Title="Scenario 1", ClassType=typeof(Scenario1)},
+ new Scenario() { Title="ContextFlyout on an element", ClassType=typeof(Scenario1)},
+ new Scenario() { Title="ContextFlyout in ListView", ClassType=typeof(Scenario2)},
+ new Scenario() { Title="ContextRequested event", ClassType=typeof(Scenario3)},
};
}
diff --git a/Samples/XamlContextMenu/cs/SampleData.cs b/Samples/XamlContextMenu/cs/SampleData.cs
index 960d9d0018..87bc94bd08 100644
--- a/Samples/XamlContextMenu/cs/SampleData.cs
+++ b/Samples/XamlContextMenu/cs/SampleData.cs
@@ -1,42 +1,32 @@
using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-namespace ContextMenuCS
+namespace SDKTemplate
{
public class SampleDataModel
{
public string Title { get; private set; }
public string ImagePath { get; private set; }
- public bool IsNew { get; private set; }
- public bool IsFlagged { get; private set; }
- public SampleDataModel(string title, string imagePath, bool isNew = false, bool isFlagged = false)
+ public SampleDataModel(string title, string imagePath)
{
this.Title = title;
this.ImagePath = imagePath;
- this.IsNew = isNew;
- this.IsFlagged = isFlagged;
}
- public override string ToString()
- {
- return this.Title;
- }
+ // Not used in sample but makes debugging easier.
+ public override string ToString() => this.Title;
- static public ObservableCollection GetSampleData()
+ static public List GetSampleData()
{
- var MyCollection = new ObservableCollection();
- MyCollection.Add(new SampleDataModel("Cliff", "Assets/cliff.jpg"));
- MyCollection.Add(new SampleDataModel("Grapes", "ms-appx:///Assets/grapes.jpg"));
- MyCollection.Add(new SampleDataModel("Rainier", "ms-appx:///Assets/Rainier.jpg", true));
- MyCollection.Add(new SampleDataModel("Sunset", "ms-appx:///Assets/Sunset.jpg", true, true));
- MyCollection.Add(new SampleDataModel("Treetops", "ms-appx:///Assets/Treetops.jpg", true));
- MyCollection.Add(new SampleDataModel("Valley", "ms-appx:///Assets/Valley.jpg", false, true));
- return MyCollection;
+ return new List() {
+ new SampleDataModel("Cliff", "Assets/cliff.jpg"),
+ new SampleDataModel("Grapes", "Assets/grapes.jpg"),
+ new SampleDataModel("Rainier", "Assets/Rainier.jpg"),
+ new SampleDataModel("Sunset", "Assets/Sunset.jpg"),
+ new SampleDataModel("Treetops", "Assets/Treetops.jpg"),
+ new SampleDataModel("Valley", "Assets/Valley.jpg"),
+ };
}
}
}
diff --git a/Samples/XamlContextMenu/cs/Scenario1.xaml.cs b/Samples/XamlContextMenu/cs/Scenario1.xaml.cs
index f8d6156e35..a5fba25dda 100644
--- a/Samples/XamlContextMenu/cs/Scenario1.xaml.cs
+++ b/Samples/XamlContextMenu/cs/Scenario1.xaml.cs
@@ -12,150 +12,37 @@
using SDKTemplate;
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
-using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Navigation;
-// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
-
-namespace ContextMenuCS
+namespace SDKTemplate
{
- ///
- /// An empty page that can be used on its own or navigated to within a Frame.
- ///
public sealed partial class Scenario1 : Page
{
- private MainPage rootPage;
- private bool _IsShiftPressed = false;
- private bool _IsPointerPressed = false;
- public List AllItems = null;
+ private MainPage rootPage = MainPage.Current;
public Scenario1()
{
this.InitializeComponent();
- AllItems = SampleDataModel.GetSampleData().ToList();
- this.DataContext = this;
- }
-
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- rootPage = MainPage.Current;
- }
-
-
- protected override void OnKeyDown(KeyRoutedEventArgs e)
- {
- // Handle Shift+F10
- // Handle MenuKey
-
- if (e.Key == Windows.System.VirtualKey.Shift)
- {
- _IsShiftPressed = true;
- }
-
- // Shift+F10
- else if (_IsShiftPressed && e.Key == Windows.System.VirtualKey.F10)
- {
- var FocusedElement = FocusManager.GetFocusedElement() as UIElement;
-
- SampleDataModel MyObject = null;
- if (FocusedElement is ContentControl)
- {
- MyObject = ((ContentControl)FocusedElement).Content as SampleDataModel;
- }
- ShowContextMenu(MyObject, FocusedElement, new Point(0, 0));
- e.Handled = true;
- }
-
- // The 'Menu' key next to Right Ctrl on most keyboards
- else if (e.Key == Windows.System.VirtualKey.Application || e.Key == Windows.System.VirtualKey.GamepadMenu)
- {
- var FocusedElement = FocusManager.GetFocusedElement() as UIElement;
- SampleDataModel MyObject = null;
- if (FocusedElement is ContentControl)
- {
- MyObject = ((ContentControl)FocusedElement).Content as SampleDataModel;
- }
- ShowContextMenu(MyObject, FocusedElement, new Point(0, 0));
- e.Handled = true;
- }
-
- base.OnKeyDown(e);
- }
-
- protected override void OnKeyUp(KeyRoutedEventArgs e)
- {
- if (e.Key == Windows.System.VirtualKey.Shift)
- {
- _IsShiftPressed = false;
- }
-
- base.OnKeyUp(e);
- }
- protected override void OnHolding(HoldingRoutedEventArgs e)
- {
- // Responding to HoldingState.Started will show a context menu while your finger is still down, while
- // HoldingState.Completed will wait until the user has removed their finger.
- if (e.HoldingState == Windows.UI.Input.HoldingState.Completed)
- {
- var PointerPosition = e.GetPosition(null);
-
- var MyObject = (e.OriginalSource as FrameworkElement).DataContext as SampleDataModel;
- ShowContextMenu(MyObject, null, PointerPosition);
- e.Handled = true;
-
- // This, combined with a check in OnRightTapped prevents the firing of RightTapped from
- // launching another context menu
- _IsPointerPressed = false;
-
- // This prevents any scrollviewers from continuing to pan once the context menu is displayed.
- // Ideally, you should find the ListViewItem itself and only CancelDirectMinpulations on that item.
- var ItemsToCancel = VisualTreeHelper.FindElementsInHostCoordinates(PointerPosition, ItemListView);
- foreach (var Item in ItemsToCancel)
- {
- var Result = Item.CancelDirectManipulations();
- }
- }
-
- base.OnHolding(e);
}
- protected override void OnPointerPressed(PointerRoutedEventArgs e)
+ private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
{
- _IsPointerPressed = true;
-
- base.OnPointerPressed(e);
+ rootPage.NotifyUser("Action: Open", NotifyType.StatusMessage);
}
- protected override void OnRightTapped(RightTappedRoutedEventArgs e)
+ private void PrintMenuItem_Click(object sender, RoutedEventArgs e)
{
- if (_IsPointerPressed)
- {
- var MyObject = (e.OriginalSource as FrameworkElement).DataContext as SampleDataModel;
-
- ShowContextMenu(MyObject, null, e.GetPosition(null));
- e.Handled = true;
- }
-
- base.OnRightTapped(e);
+ rootPage.NotifyUser("Action: Print", NotifyType.StatusMessage);
}
- private void ShowContextMenu(SampleDataModel data, UIElement target, Point offset)
+ private void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
{
- var MyFlyout = this.Resources["SampleContextMenu"] as MenuFlyout;
-
- System.Diagnostics.Debug.WriteLine("MenuFlyout shown '{0}', '{1}'", target, offset);
-
- MyFlyout.ShowAt(target, offset);
+ rootPage.NotifyUser("Action: Delete", NotifyType.StatusMessage);
}
}
}
diff --git a/Samples/XamlContextMenu/cs/Scenario2.xaml.cs b/Samples/XamlContextMenu/cs/Scenario2.xaml.cs
new file mode 100644
index 0000000000..a60c46045b
--- /dev/null
+++ b/Samples/XamlContextMenu/cs/Scenario2.xaml.cs
@@ -0,0 +1,61 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using SDKTemplate;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Windows.Foundation;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+
+namespace SDKTemplate
+{
+ public sealed partial class Scenario2 : Page
+ {
+ private MainPage rootPage = MainPage.Current;
+ public List AllItems = SampleDataModel.GetSampleData();
+
+ public Scenario2()
+ {
+ this.InitializeComponent();
+ }
+
+ private SampleDataModel GetDataModelForCurrentListViewFlyout()
+ {
+ // Obtain the ListViewItem for which the user requested a context menu.
+ var listViewItem = SharedFlyout.Target;
+
+ // Get the data model for the ListViewItem.
+ return (SampleDataModel)ItemListView.ItemFromContainer(listViewItem);
+ }
+
+ private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Open", NotifyType.StatusMessage);
+ }
+
+ private void PrintMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Print", NotifyType.StatusMessage);
+ }
+
+ private void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Delete", NotifyType.StatusMessage);
+ }
+ }
+}
diff --git a/Samples/XamlContextMenu/cs/Scenario3.xaml.cs b/Samples/XamlContextMenu/cs/Scenario3.xaml.cs
new file mode 100644
index 0000000000..8a371f2365
--- /dev/null
+++ b/Samples/XamlContextMenu/cs/Scenario3.xaml.cs
@@ -0,0 +1,100 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+using SDKTemplate;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Windows.Foundation;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+
+// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
+
+namespace SDKTemplate
+{
+ public sealed partial class Scenario3 : Page
+ {
+ private MainPage rootPage = MainPage.Current;
+ public List AllItems = SampleDataModel.GetSampleData();
+ private MenuFlyout sharedFlyout;
+
+ public Scenario3()
+ {
+ this.InitializeComponent();
+ sharedFlyout = (MenuFlyout)Resources["SampleContextMenu"];
+ }
+
+ private void ListView_ContextRequested(UIElement sender, ContextRequestedEventArgs e)
+ {
+ // Walk up the tree to find the ListViewItem.
+ // There may not be one if the click wasn't on an item.
+ var requestedElement = (FrameworkElement)e.OriginalSource;
+ while ((requestedElement != sender) && !(requestedElement is ListViewItem))
+ {
+ requestedElement = (FrameworkElement)VisualTreeHelper.GetParent(requestedElement);
+ }
+ if (requestedElement != sender)
+ {
+ // The context menu request was indeed for a ListViewItem.
+ var model = (SampleDataModel)ItemListView.ItemFromContainer(requestedElement);
+ Point point;
+ if (e.TryGetPosition(requestedElement, out point))
+ {
+ rootPage.NotifyUser($"Showing flyout for {model.Title} at {point}", NotifyType.StatusMessage);
+ sharedFlyout.ShowAt(requestedElement, point);
+ }
+ else
+ {
+ // Not invoked via pointer, so let XAML choose a default location.
+ rootPage.NotifyUser($"Showing flyout for {model.Title} at default location", NotifyType.StatusMessage);
+ sharedFlyout.ShowAt(requestedElement);
+ }
+
+ e.Handled = true;
+ }
+ }
+
+ private void ListView_ContextCanceled(UIElement sender, RoutedEventArgs args)
+ {
+ sharedFlyout.Hide();
+ }
+
+ private SampleDataModel GetDataModelForCurrentListViewFlyout()
+ {
+ // Obtain the ListViewItem for which the user requested a context menu.
+ var listViewItem = sharedFlyout.Target;
+
+ // Get the data model for the ListViewItem.
+ return (SampleDataModel)ItemListView.ItemFromContainer(listViewItem);
+ }
+
+ private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Open", NotifyType.StatusMessage);
+ }
+
+ private void PrintMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Print", NotifyType.StatusMessage);
+ }
+
+ private void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ SampleDataModel model = GetDataModelForCurrentListViewFlyout();
+ rootPage.NotifyUser($"Item: {model.Title}, Action: Delete", NotifyType.StatusMessage);
+ }
+ }
+}
diff --git a/Samples/XamlContextMenu/cs/Scenario1.xaml b/Samples/XamlContextMenu/shared/Scenario1.xaml
similarity index 66%
rename from Samples/XamlContextMenu/cs/Scenario1.xaml
rename to Samples/XamlContextMenu/shared/Scenario1.xaml
index f47a5e07d2..9f68bf626f 100644
--- a/Samples/XamlContextMenu/cs/Scenario1.xaml
+++ b/Samples/XamlContextMenu/shared/Scenario1.xaml
@@ -11,36 +11,15 @@
//*********************************************************
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ mc:Ignorable="d">
+
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-This scenario shows how to hook up a context menu for mouse, keyboard, and touch.
-For keyboard users, Shift+F10 or the 'application' key invokes the context menu.
-For touch, press and hold to invoke the menu.
-For mouse, right click to invoke the menu.
-For game controller, press the Menu button to invoke the menu.
-
-When running on a desktop, MenuFlyout.ShowAt allows context menus to show outside the application window, such as when right clicking near the edges of your applicaiton.
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ If you set the ContextFlyout for an element, the flyout will be displayed
+ when the user requests the context menu. After putting focus on the button
+ below, request a context menu by pressing Shift+F10 (keyboard),
+ pressing the 'Application' key (keyboard),
+ or pressing the Menu button (game controller).
+ You can also right-click (mouse) or press-and-hold (touch) directly on the button.
+
+
+ This scenario also demonstrates custom styling for the MenuFlyoutItem.
+
+
+
+
+
diff --git a/Samples/XamlContextMenu/shared/Scenario2.xaml b/Samples/XamlContextMenu/shared/Scenario2.xaml
new file mode 100644
index 0000000000..920b3f8662
--- /dev/null
+++ b/Samples/XamlContextMenu/shared/Scenario2.xaml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ This scenario attaches a ContextFlyout to each ListViewItem.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Samples/XamlContextMenu/shared/Scenario3.xaml b/Samples/XamlContextMenu/shared/Scenario3.xaml
new file mode 100644
index 0000000000..bbbb8ffd35
--- /dev/null
+++ b/Samples/XamlContextMenu/shared/Scenario3.xaml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The ContextRequested event allows an app to display custom context UI.
+ This scenario responds to the ContextRequested event by displaying a MenuFlyout,
+ resulting in the same effect as the "ContextFlyout in ListView" scenario.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+