I would like to ask the user to pin to start the default live tile when he runs the app for the first time in Windows 10 (Universal Windows Platform).
I know that for a secondaryTile you can use the following code:
var result = await secondaryTile.RequestCreateAsync();
What is the equivalent for a default live tile?
Since this question was asked, there has been a new addition to the UWP API: StartScreenManager in V4 which lets you pin the app's default tile to the start screen. Here is a Command that lets you do it - and is disabled if the tile is already there. It handles the Window Activated event because the user could remove the pinned tile manually:
using System;
using System.Linq;
using System.Windows.Input;
using Windows.ApplicationModel;
using Windows.Foundation.Metadata;
using Windows.UI.Core;
using Windows.UI.StartScreen;
using Windows.UI.Xaml;
namespace Synergist
{
/// <summary>
/// Pin the first entry in the package's app list to the start screen
/// </summary>
public class PinToStartCommand : ICommand
{
private bool _canExecute;
/// <summary>
/// Initializes a new instance of the PinToStartCommand class.
/// </summary>
public PinToStartCommand()
{
Window.Current.Activated += Current_Activated;
}
/// <summary>
/// Can execute changed event handler
/// </summary>
public event EventHandler CanExecuteChanged;
/// <summary>
/// returns true if the StartScreenManager exists
/// </summary>
/// <param name="parameter">the parameter is not used</param>
/// <returns>true if the app is not pinned to the start screen and the API is available</returns>
public bool CanExecute(object parameter)
{
return _canExecute;
}
/// <summary>
/// Pin the app to the start screen
/// </summary>
/// <param name="parameter">the parameter is not used.</param>
public async void Execute(object parameter)
{
if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
{
var entries = await Package.Current.GetAppListEntriesAsync();
var firstEntry = entries.FirstOrDefault();
if (firstEntry == null)
return;
var startScreenmanager = StartScreenManager.GetDefault();
var containsEntry = await startScreenmanager.ContainsAppListEntryAsync(firstEntry);
if (containsEntry)
return;
if (await startScreenmanager.RequestAddAppListEntryAsync(firstEntry))
{
_canExecute = false;
CanExecuteChanged?.Invoke(this, new EventArgs());
}
}
}
private async void Current_Activated(object sender, WindowActivatedEventArgs e)
{
var entries = await Package.Current.GetAppListEntriesAsync();
var firstEntry = entries.FirstOrDefault();
if (firstEntry == null)
{
_canExecute = false;
return;
}
if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
{
var startScreenmanager = StartScreenManager.GetDefault();
_canExecute = !await startScreenmanager.ContainsAppListEntryAsync(firstEntry);
CanExecuteChanged?.Invoke(this, new EventArgs());
}
}
}
}
there is no way to pin the default live tile programmatically. you can only pin secondary tiles.
the default tile is always available programmatically but cannot be pinned by the app. only by the user itself from the list of apps.
your best solution is to create a secondary tile and ask to pin that. (would even be better to make the secondary tile to go to a specific area of the app as that is what secondary apps are for)
here is a guide on how to implement the secondary apps and how to pin them: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868249.aspx
Related
Im currently facing a weird problem with the Microsoft Kinect SDK 2.0 Browser Sample code of Discrete Gesture Basics-WPF
Objective: is to add my own recording of the gesture in filename.gbd into the database and able to extract the gesture inside.
Problem: When i changed the initial name from 'Seated.gbd' to 'RightHandHandsUp.gbd' The error occured below.
However, if i were to rename my 'RightHandHandsUp.gbd' file to 'Seated.gbd' ( the default), it would work. Which is weird, but i suspect there is some binding somewhere in the program but i have already tried searching the entire project for the keyword.
Thanks in advance!!
Error Message:
System.Windows.Markup.XamlParseException: ''The invocation of the constructor on type 'Microsoft.Samples.Kinect.DiscreteGestureBasics.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.'
With 2 inner exceptions:
InvalidOperationException: This API has returned an exception from an HRESULT: 0x80004005
And
COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
so in the GestureDetector.cs file where i changed the name of the file.
//------------------------------------------------------------------------------
// <copyright file="GestureDetector.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace Microsoft.Samples.Kinect.DiscreteGestureBasics
{
using System;
using System.Collections.Generic;
using Microsoft.Kinect;
using Microsoft.Kinect.VisualGestureBuilder;
/// <summary>
/// Gesture Detector class which listens for VisualGestureBuilderFrame events from the service
/// and updates the associated GestureResultView object with the latest results for the 'Seated' gesture
/// </summary>
public class GestureDetector : IDisposable
{
/// <summary> Path to the gesture database that was trained with VGB </summary>
private readonly string gestureDatabase = #"Database\RightHandHandsUp.gbd";
/// <summary> Name of the discrete gesture in the database that we want to track </summary>
private readonly string seatedGestureName = "HandsUp_Right";
/// <summary> Gesture frame source which should be tied to a body tracking ID </summary>
private VisualGestureBuilderFrameSource vgbFrameSource = null;
/// <summary> Gesture frame reader which will handle gesture events coming from the sensor </summary>
private VisualGestureBuilderFrameReader vgbFrameReader = null;
/// <summary>
/// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
/// </summary>
/// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
/// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView)
{
if (kinectSensor == null)
{
throw new ArgumentNullException("kinectSensor");
}
if (gestureResultView == null)
{
throw new ArgumentNullException("gestureResultView");
}
this.GestureResultView = gestureResultView;
// create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;
// open the reader for the vgb frames
this.vgbFrameReader = this.vgbFrameSource.OpenReader();
if (this.vgbFrameReader != null)
{
this.vgbFrameReader.IsPaused = true;
this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived;
}
// load the 'Seated' gesture from the gesture database
using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
{
// we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures),
// but for this program, we only want to track one discrete gesture from the database, so we'll load it by name
foreach (Gesture gesture in database.AvailableGestures)
{
if (gesture.Name.Equals(this.seatedGestureName))
{
this.vgbFrameSource.AddGesture(gesture);
}
}
}
}
/// <summary> Gets the GestureResultView object which stores the detector results for display in the UI </summary>
public GestureResultView GestureResultView { get; private set; }
/// <summary>
/// Gets or sets the body tracking ID associated with the current detector
/// The tracking ID can change whenever a body comes in/out of scope
/// </summary>
public ulong TrackingId
{
get
{
return this.vgbFrameSource.TrackingId;
}
set
{
if (this.vgbFrameSource.TrackingId != value)
{
this.vgbFrameSource.TrackingId = value;
}
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the detector is currently paused
/// If the body tracking ID associated with the detector is not valid, then the detector should be paused
/// </summary>
public bool IsPaused
{
get
{
return this.vgbFrameReader.IsPaused;
}
set
{
if (this.vgbFrameReader.IsPaused != value)
{
this.vgbFrameReader.IsPaused = value;
}
}
}
/// <summary>
/// Disposes all unmanaged resources for the class
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes the VisualGestureBuilderFrameSource and VisualGestureBuilderFrameReader objects
/// </summary>
/// <param name="disposing">True if Dispose was called directly, false if the GC handles the disposing</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.vgbFrameReader != null)
{
this.vgbFrameReader.FrameArrived -= this.Reader_GestureFrameArrived;
this.vgbFrameReader.Dispose();
this.vgbFrameReader = null;
}
if (this.vgbFrameSource != null)
{
this.vgbFrameSource.TrackingIdLost -= this.Source_TrackingIdLost;
this.vgbFrameSource.Dispose();
this.vgbFrameSource = null;
}
}
}
/// <summary>
/// Handles gesture detection results arriving from the sensor for the associated body tracking Id
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void Reader_GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
{
VisualGestureBuilderFrameReference frameReference = e.FrameReference;
using (VisualGestureBuilderFrame frame = frameReference.AcquireFrame())
{
if (frame != null)
{
// get the discrete gesture results which arrived with the latest frame
IReadOnlyDictionary<Gesture, DiscreteGestureResult> discreteResults = frame.DiscreteGestureResults;
if (discreteResults != null)
{
// we only have one gesture in this source object, but you can get multiple gestures
foreach (Gesture gesture in this.vgbFrameSource.Gestures)
{
if (gesture.Name.Equals(this.seatedGestureName) && gesture.GestureType == GestureType.Discrete)
{
DiscreteGestureResult result = null;
discreteResults.TryGetValue(gesture, out result);
if (result != null)
{
// update the GestureResultView object with new gesture result values
this.GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence);
}
}
}
}
}
}
}
/// <summary>
/// Handles the TrackingIdLost event for the VisualGestureBuilderSource object
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void Source_TrackingIdLost(object sender, TrackingIdLostEventArgs e)
{
// update the GestureResultView object to show the 'Not Tracked' image in the UI
this.GestureResultView.UpdateGestureResult(false, false, 0.0f);
}
}
}
In my case I didn't know that DiscreteGestureBasics is using AdaBoostTech.dll and RFRProgressTech.dll. I copied directory vgtech from DiscreteGestureBuilder example bin directory to my other project bin directory and everything works fine.
I'm having trouble with coding my Esurvey application(using Windows Store C# XAML) and I really need help. I need to create a .csv database which contains all results(radiobutton selections and text inputs) but I'm not sure where to even start.
Can someone help me with this? I'm using Visual Studio Community 2013.
using FYPPrototype1.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
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;
using Windows.UI.Popups;
// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
namespace FYPPrototype1
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
///
public sealed partial class SurveyPage1 : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public SurveyPage1()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="sender">
/// The source of the event; typically <see cref="NavigationHelper"/>
/// </param>
/// <param name="e">Event data that provides both the navigation parameter passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
/// a dictionary of state preserved by this page during an earlier
/// session. The state will be null the first time a page is visited.</param>
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
if (e.PageState != null && e.PageState.ContainsKey("rbNumber1") && e.PageState.ContainsKey("rbNumber2") && e.PageState.ContainsKey("rbNumber3") && e.PageState.ContainsKey("rbNumber4"))
{
radioExcellent.IsChecked = (bool)e.PageState["rbNumber1"];
radioGood.IsChecked = (bool)e.PageState["rbNumber2"];
radioPoor.IsChecked = (bool)e.PageState["rbNumber3"];
radioAverage.IsChecked = (bool)e.PageState["rbNumber4"];
}
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
e.PageState["rbNumber1"] = radioExcellent.IsChecked;
e.PageState["rbNumber2"] = radioGood.IsChecked;
e.PageState["rbNumber3"] = radioPoor.IsChecked;
e.PageState["rbNumber4"] = radioAverage.IsChecked;
}
#region NavigationHelper registration
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
/// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
#endregion
private async void Button_S1_S2(object sender, RoutedEventArgs e)
{
if (radioExcellent.IsChecked != true && radioGood.IsChecked != true && radioAverage.IsChecked != true && radioPoor.IsChecked != true)
{
MessageDialog md = new MessageDialog("Please select an option before proceeding!");
await md.ShowAsync();
}
else
{
this.Frame.Navigate(typeof(SurveyPage2));
}
}
}
}
Here is a screenshot of my application in case you need a reference.
This is the output that my teacher wants but I have no idea how to make it as shown :(
You can do it this way where "greetingOutputText" is the key
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
// Restore values stored in session state.
if (e.PageState != null && e.PageState.ContainsKey("greetingOutputText"))
{
greetingOutput.Text = e.PageState["greetingOutputText"].ToString();
}
}
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
e.PageState["greetingOutputText"] = greetingOutput.Text;
}
This link will help you.
I'm having trouble with coding my Esurvey application(using Windows Store C# XAML) and I really need help. I need to create a .csv database which contains all results(radiobutton selections and text inputs) but I'm not sure where to even start.
Can someone help me with this? I'm using Visual Studio Community 2013.
using FYPPrototype1.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
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;
using Windows.UI.Popups;
// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
namespace FYPPrototype1
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
///
public sealed partial class SurveyPage1 : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public SurveyPage1()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="sender">
/// The source of the event; typically <see cref="NavigationHelper"/>
/// </param>
/// <param name="e">Event data that provides both the navigation parameter passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
/// a dictionary of state preserved by this page during an earlier
/// session. The state will be null the first time a page is visited.</param>
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
if (e.PageState != null && e.PageState.ContainsKey("rbNumber1") && e.PageState.ContainsKey("rbNumber2") && e.PageState.ContainsKey("rbNumber3") && e.PageState.ContainsKey("rbNumber4"))
{
radioExcellent.IsChecked = (bool)e.PageState["rbNumber1"];
radioGood.IsChecked = (bool)e.PageState["rbNumber2"];
radioPoor.IsChecked = (bool)e.PageState["rbNumber3"];
radioAverage.IsChecked = (bool)e.PageState["rbNumber4"];
}
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
e.PageState["rbNumber1"] = radioExcellent.IsChecked;
e.PageState["rbNumber2"] = radioGood.IsChecked;
e.PageState["rbNumber3"] = radioPoor.IsChecked;
e.PageState["rbNumber4"] = radioAverage.IsChecked;
}
#region NavigationHelper registration
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
/// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
#endregion
private async void Button_S1_S2(object sender, RoutedEventArgs e)
{
if (radioExcellent.IsChecked != true && radioGood.IsChecked != true && radioAverage.IsChecked != true && radioPoor.IsChecked != true)
{
MessageDialog md = new MessageDialog("Please select an option before proceeding!");
await md.ShowAsync();
}
else
{
this.Frame.Navigate(typeof(SurveyPage2));
}
}
}
}
Here is a screenshot of my application in case you need a reference.
This is the output that my teacher wants but I have no idea how to make it as shown :(
I'm trying to code an ESurvey application. I have a list of radio buttons in each page (A total of 7 pages), and I would like to make the radio buttons save its check state when the respondent clicks on the previous page.
using FYPPrototype1.Common;
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;
using Windows.UI.Popups;
// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
namespace FYPPrototype1
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
public sealed partial class SurveyPage2 : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public SurveyPage2()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="sender">
/// The source of the event; typically <see cref="NavigationHelper"/>
/// </param>
/// <param name="e">Event data that provides both the navigation parameter passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
/// a dictionary of state preserved by this page during an earlier
/// session. The state will be null the first time a page is visited.</param>
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
}
#region NavigationHelper registration
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
/// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
#endregion
private async void Button_S2_S3(object sender, RoutedEventArgs e)
{
if (RadioaAgree.IsChecked != true && RadioaNeutral.IsChecked != true && RadioaDisagree.IsChecked != true)
{
MessageDialog md = new MessageDialog("One or more options not selected. Please complete all options before proceeding!");
await md.ShowAsync();
}
else if (RadiobAgree.IsChecked != true && RadiobNeutral.IsChecked != true && RadiobDisagree.IsChecked != true)
{
MessageDialog md = new MessageDialog("One or more options not selected. Please complete all options before proceeding!");
await md.ShowAsync();
}
else if (RadiocAgree.IsChecked != true && RadiocNeutral.IsChecked != true && RadiocDisagree.IsChecked != true)
{
MessageDialog md = new MessageDialog("One or more options not selected. Please complete all options before proceeding!");
await md.ShowAsync();
}
else if (RadiodAgree.IsChecked != true && RadiodNeutral.IsChecked != true && RadiodDisagree.IsChecked != true)
{
MessageDialog md = new MessageDialog("One or more options not selected. Please complete all options before proceeding!");
await md.ShowAsync();
}
else
{
this.Frame.Navigate(typeof(SurveyPage3));
}
}
}
}
Much appreciated to all the kind coders out there helping me out!
You can simply store a local variable, like a boolean, and when returning to that page check for the variable value and change radioButtons state accordingly ;)
// these is the namespace of your class
namespace FYPPrototype1
{
// these is the region of your class, where all functions and variables are stored
public sealed partial class SurveyPage2 : Page
{
// these are local variables
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
// this is your class constructor
public SurveyPage2()
{
InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
.
.
.
}
}
Now for achieve what you need, you have to do a more complex thing, as you can see you have a load and a save function, that is navigationHelper_LoadState and navigationHelper_SaveState, you can store and load there radioButtons's state ;)
For more understanding on how to manage these functions refer to these page, it explain it quite well ;): http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2014/05/23/windows-phone-8-1-frame-page-navigationhelper-suspensionmanager.aspx
I have a numericUpDown control (Windows Forms).
I want to listen to the ValueChanged event.
I set it in the properties and it works.
But:
I want that i can "scroll" up or down. (If I make this longer it will be faster)
When I'm done with the "scroll", I want that the event xyz is fired now and not during the scrolling.
How can I do that?
Try using the mouseup event. It fires when you take your finger off of the left mouse button, so in theory it should solve your issue.
[Edited by James]
Try this control on your form.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Example.CustomControl
{
/// <summary>
/// Provides an extra event for the numericUpDown control that fires after the value stops scrolling.
/// </summary>
public class NumericDelayedChange : NumericUpDown
{
/// <summary>
/// Flag that the value has actually changed.
/// </summary>
/// <devdoc>
/// Just in case the control was clicked somewhere other than the up/down buttons.
/// </devdoc>
private bool valueHasChanged = false;
/// <summary>
/// Fires when the value has stopped being scrolled.
/// </summary>
public event EventHandler OnAfterScollValueChanged;
/// <summary>
/// Captures that value as having changed.
/// </summary>
/// <param name="e"></param>
protected override void OnValueChanged(EventArgs e)
{
valueHasChanged = true;
base.OnValueChanged(e);
}
/// <summary>
/// Captures the mouse up event to identify scrolling stopped when used in combination with the value changed flag.
/// </summary>
/// <param name="mevent"></param>
protected override void OnMouseUp(MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
{
PerformOnAfterScollValueChanged();
}
}
/// <summary>
/// Captures the key up/down events to identify scrolling stopped when used in combination with the value changed flag.
/// </summary>
/// <param name="mevent"></param>
protected override void OnKeyUp(KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{
PerformOnAfterScollValueChanged();
}
base.OnKeyUp(e);
}
/// <summary>
/// Checks the value changed flag and fires the OnAfterScollValueChanged event.
/// </summary>
private void PerformOnAfterScollValueChanged()
{
if (valueHasChanged)
{
valueHasChanged = false;
if (OnAfterScollValueChanged != null) { OnAfterScollValueChanged(this, new EventArgs()); }
}
}
}
}
You need to define what is I'm done with the scroll. This could be removing the mouse from the scroll button, or a certain time passed since the last click. In any case, I don't think you can cause the event not to run, but you can do some checks in the event handler. For example:
private DateTime? lastClickTime;
public void MyUpDown_ValueChanged(object sender, EventArgs e)
{
if (lastClickTime != null && DateTime.Now.Subtract(lastClickTime.Value).Seconds > someInterval)
{
// Do the work
}
lastClickTime = DateTime.Now
}
But, as I said, you need first to define what is I'm done. This code is not perfect.
Here's a direct way of approaching the problem:
Just check if a mouse button is being pressed with Control.MouseButtons, like this:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
//don't update until done scrolling
if (Control.MouseButtons == MouseButtons.None)
{
// Do the work
}
}
Here's how I solved this problem:
A task checks a "valueIsChanging" flag. This flag is set by the ValueChanged event. After this flag stops being set to True by the ValueChanged event, the while loop completes and your code is executed.
Task waitForValueSettleTask;
volatile bool valueIsChanging; // marked volaltile since it is access by multiple threads (the GUI thread, and the task)
private void numericUpDown_ValueChanged(object sender, EventArgs e)
{
valueIsChanging = true;
if (waitForValueSettleTask == null || waitForValueSettleTask != null &&
(waitForValueSettleTask.IsCanceled || waitForValueSettleTask.IsCompleted || waitForValueSettleTask.IsFaulted))
{
waitForValueSettleTask = Task.Run(() =>
{
while (valueIsChanging)
{
valueIsChanging = false;
Thread.Sleep(1000); // Set this to whatever settling time you'd like
}
// Your code goes here
});
}
}