RecognizeWithUIAsync cannot use await operator - windows-phone-8

I downloaded VS 2013 for Windows and started a new Windows Phone Silverlight application, placed a button and tried to make the example here work, but couldn't because of the await operator:
The examples on the official MSDN site are pretty straight forward, some are like three lines and I can't find anything on the matter. What gives?

You have to add async to your method to be able to use await into it:
private async void Button_Click(object sender, RoutedEventArgs e)

The error message is self-explanatory, you need to mark your method as async:
private async void Button_Click(object sender, RoutedEventArgs e)

Related

Store update of 8.1 app to uwp app

I have a Windows Phone 8.1 app in the store. Now I have created an uwp update. My question is:
If I load an update of the app into the store and an user does this update. Is the app just overwritten or deinstalled and then new installed? And are the saved settings in ApplicationData.Current.LocalSettings deleted?
thx newone
TL;DR; - It preserves data in LocalFolder and LocalSettings when updating from WP8.1 Runtime to UWP (tested with mobile on device with Insider preview - Fast ring).
I've run similar test, like the last time:
I've published a Beta version of the App - WP8.1 Runtime.
After successful installation on the Phone, I've created a file in LocalFolder and set value in LocalSettings (see code below),
I've submitted an update - went to Store, selected the App, clicked Update then Packages, after a while, browse your files and chosen the new generated appxbundle (I have not deleted the old WP8.1 package), save and submit.
After some time my Phone is notified that there is an update for the App - I click update
After successful installation, I see that it's a new App, I click my special button to check LocalFolder and value in LocalSettings - I see that there are old values from WP8.1 version.
Code for buttons used to test:
private async void Generate_Click(object sender, RoutedEventArgs e)
{
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.txt");
await FileIO.WriteTextAsync(file, "Something inside");
}
private async void CheckFile_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("test.txt");
string text = await FileIO.ReadTextAsync(file);
await new MessageDialog($"File exists = {text}").ShowAsync();
}
catch (Exception) { await new MessageDialog("File desnt exists").ShowAsync(); }
}
private void GenerateSetting_Click(object sender, RoutedEventArgs e) => ApplicationData.Current.LocalSettings.Values["CHECK"] = "Test value";
private async void CheckSetting_Click(object sender, RoutedEventArgs e)
{
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("CHECK"))
await new MessageDialog($"Setting exists = {ApplicationData.Current.LocalSettings.Values["CHECK"]}").ShowAsync();
else await new MessageDialog("Setting doesn't exist").ShowAsync();
}

Windows Phone navigation to other page

I'm trying to navigate to another page. I'm using the MVVM pattern. So my button is binded to a command:
private ICommand inscriptionPage;
public ICommand InscriptionPage
{
get
{
if (this.inscriptionPage == null)
this.inscriptionPage = new MyCommand(() => callInscriptionFunction());
return this.inscriptionPage;
}
}
public void callInscriptionFunction()
{
PhoneApplicationPage nav = new PhoneApplicationPage();
nav.NavigationService.Navigate(new Uri("Views/Registration/Registration.xaml", UriKind.Relative));
}
I have this Exception at the last line:
object reference not set to an instance of an object
I check on the web, tried different option, but this error is still there.
Edit: I tried to change the command to put it directly in the code behind. But I have a Debugger.break error.
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("Views/Registration/Registration.xaml", UriKind.Relative));
}
Thanks.
First, your Uri should begin with a slash, so change new Uri("Views/Registration/Registration.xaml", UriKind.Relative) to new Uri("/Views/Registration/Registration.xaml", UriKind.Relative). This should make your code behind work.
Second, creating a PhoneApplicationPage is a really strange and wrong idea. If you are not using a MVVM framework that provides navigation service, usu this
App.RootFrame.Navigate(new Uri("/Views/Registration/Registration.xaml", UriKind.Relative))

nokia mixradio api to get top artist list in new realease

I'm working with my new app for Windows phone and using Nokia music api which is now Nokia mix radio api. There are many changes in it and MusicClientAsync is no longer functional.
I want to get list of top artist in user region. I'm trying to use following code but it is showing an error and I'm not able to find any documentation.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MusicClient client = new MusicClient(MyAppId);
ListResponse{<MusicItem>} result = await client.GetTopArtistsAsync();
}
What you need to do, is to add the async keyworkd to your Button_Click method:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
MusicClient client = new MusicClient(MyAppId);
ListResponse{<MusicItem>} result = await client.GetTopArtistsAsync();
}
See how i add async word after private and before void this way your Button_Click_1 method can use the await keyword. THis way the call to GetTopArtistsAsync is going to work.

Get the delta value from PointeWheelChanged event for WinRT

Is there any way to get the delta value from PointeWheelChanged event in WinRT?
The following works in the RTM of Windows Runtime, it will log the result to the Debug window. Positive values are up (away from you), negative values are scrolling down (towards you). Important is to set handled to true so that this event doesn't bubble further up the UI elements.
private void ZoomPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.GetCurrentPoint(this).Properties.MouseWheelDelta);
e.Handled = true;
}
Following code works well,
private void PointerWheelChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
var wheelDelta = args.CurrentPoint.Properties.MouseWheelDelta;
// do something with the delta
}

how to extract html code for website using iframe and silverlight

I need to load a specific webpage from a site that has multiple images on the site. I need to extract these images but I can't do this manually because the names of each image have no pattern and there will be hundreds of sites. I have a silverlight application to load the webpage in an iframe and I intended on extracting the html for this webpage and then retrieving the image source for each image from the extracted code and then populating a listbox.
I can load the web page in iframe with no problem, but I don't know how to retrieve the html code for the webpage.
public Page()
{
InitializeComponent();
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null)
{
myFrame.SetStyleAttribute("width", "1024");
myFrame.SetStyleAttribute("height", "768");
myFrame.SetAttribute("src", txtURI.Text);
myFrame.SetStyleAttribute("left", "0");
myFrame.SetStyleAttribute("top", "50");
myFrame.SetStyleAttribute("visibility", "visible");
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Button_Click(sender, e);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null) myFrame.SetAttribute("src", txtURI.Text);
}
private void txtURI_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
this.Button_Click(sender, e);
}
The following article may offer some help:
http://jesseliberty.com/2010/05/03/screen-scraping-when-all-you-have-is-a-hammer/