Windows Phone page navigation does not work - c#

I'm new in creating apps for Windows Phone. I've got problem with redirecting to another page. I've created blank page with HyperlinkButtonand in .cs file I wrote this:
private void but_elf_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(Elfy));
}
In xaml:
<HyperlinkButton x:Name="but_elf" Content="Elfy"
HorizontalAlignment="Center" Margin="100,125,100,255" Grid.Row="1"
VerticalAlignment="Center" Width="200" Height="70" />
When I launch app and click on the button - nothing happens. There are no errors, no messages. I've tried to put NavigateUri in button's property but after pressing button (in launched app) the message has shown: "You need to install an app for this task. Would you like to search for one in the Store?" After pressing "Yes" the app says: "Sorry, no apps found".
How to figure out this problem? I'm creating app for Windows Phone 8.1 in .NET Framework 4.5. Thanks for any help.

You are missing a reference for the 'Click'-event handler. Please change your XAML to this:
<HyperlinkButton x:Name="but_elf" Content="Elfy"
HorizontalAlignment="Center" Margin="100,125,100,255" Grid.Row="1"
VerticalAlignment="Center" Width="200" Height="70" Click="but_elf_Click" />
Please see:
C# Documentation for Click on MSDN
C# Documentation for HyperlinkButton on MSDN

Related

Deleting cookies doesn't work with Webview2

I'm trying to create an app to follow new chapters from my favorite website and get an alert when a new one is online.
The website is limited to 10 chapter and, in a regulat browser, deleting the cookies is enouth to be "a new guest" :
I use a Webview2 component (C# WPF) and the following code is not working :
<Wpf:WebView2 Source="https://www.wuxiaworld.com/novel/return-of-the-disaster-class-hero/rdch-chapter-1" x:Name="wbv2Test" HorizontalAlignment="Left" Height="600" VerticalAlignment="Top" Width="500"/>
<Button Content="Delete cookies" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
private void Button_Click_1(object sender, RoutedEventArgs e)
{
wbv2Test.CoreWebView2.CookieManager.DeleteAllCookies();
}
I can spam the button, click once after each chapter displayed, this is always the limitation at the 11th chapter.
If I try with google chrome, this is enouth to remove the limitation :
I even try to create a new webview2 object but it doesn't change anything :
wbv2Test?.Dispose();
wbv2Test = new WebView2();
[...]
I have no idea why it doesn't working...

Open URL in default Web Browser. Windows Phone 8.0 app

I have a hyperlink inside a Text block. I want it to open the link int he web browser, but when I Click it I get a popup saying
"Search an app in the store"
and my app crashes.....
my XAML code is:
<TextBlock HorizontalAlignment="Right" Height="49" Margin="0,0,10,0" TextWrapping="Wrap" Width="326" Foreground="Black" FontSize="16">
<TextBlock.Inlines>
<Hyperlink Click="Hyperlink_Click" NavigateUri="www.bing.com">
<Hyperlink.Foreground>
<ImageBrush Stretch="Fill" ImageSource="Assets/Proceed.png"/>
</Hyperlink.Foreground>Don't have a Selfcare Account ? Register here.</Hyperlink>
</TextBlock.Inlines>
<!--<Hyperlink xml:space="preserve" Foreground="#000" FontSize="16">Don't have a Mobitel Selfacre Account ? Register here. </Hyperlink>-->
</TextBlock>
my CS code is:
private async void Hyperlink_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
{
await Launcher.LaunchUriAsync(new Uri("www.google.com"));
}
Kindly help me fix it... Any kind of help is appreciated....
Change the uri from www.bing.com to http://www.bing.com. It needs the protocol to determine the application it uses to start the url with.
Check these links for more information:
Auto-launching apps using file and URI associations for Windows Phone 8
URI schemes for launching built-in apps for Windows Phone 8
Reserved file and URI associations for Windows Phone 8

Windows Phone 8.1 Hyperlink button and save state

I have a hyperlink button in a pivot that navigates to a Url contained in an object in the ViewModel. When I press the button, I navigate to the url. But when I press the hardware back button, the phone navigates back to the start page.
<HyperlinkButton Content="Read More"
NavigateUri="{Binding Citation}"
BorderBrush="White"
BorderThickness="4"
Grid.Row="2"
HorizontalAlignment="Stretch"
Margin="10" />
When the debugger is attached, the back button navigates back to the app, which is what I want it to do. When it's not attached, and i've tested this on 5 devices and all the emulators, it goes back to the Start page list, and all the input that was supplied to the app is lost. The app seems to be cleared from memory completely. Help? PS I am working in Windows Phone 8.1 RT, not a shared app.
Well, it seems as if I was approaching this the wrong way. Something new in Windows Phone 8.1 RT is the WebView. So no longer does the OS open an IE instance, you can open a webpage inline a grid. So:
<Button Content="Read More"
BorderBrush="White"
BorderThickness="4"
Grid.Row="2"
HorizontalAlignment="Stretch"
Margin="10"
Click="Citation_Click"/>
and then
private void Citation_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(WebViewPage), this.equation.Citation);
}
And in the WebViewPage.xaml.cs:
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
Uri nav = new Uri(e.NavigationParameter as string);
_webView.Navigate(nav);
}
where _webView is defined as:
<Grid>
<WebView x:Name="_webView"/>
</Grid>
in WebPageView.xaml

How do always display the Numeric keyboard in windows phone 8?

I'm working on windows phone 8 app, I had a page which inputs number for that I gave code like this,
<TextBox Name="txtNumber" Height="Auto" Margin="0,10,0,510" >
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Number" />
</InputScope>
</TextBox.InputScope>
</TextBox>
by the above code; It display the numeric keyboard when I place the cursor to type; But I need a fixed keyboard which is always visible and if we type it has to enter the value to the textbox.
Would somebody please tell me how to do that.
Try this on for size:
Xaml:
<Grid
x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0"
Loaded="ContentPanel_Loaded">
<TextBox
Name="TB1"
HorizontalAlignment="Left"
Height="72"
Margin="0,74,0,0"
VerticalAlignment="Top"
Width="456"
InputScope="Number"/>
</Grid>
Code:
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
// Turn on Tab Stops. You can set this in XAML as well.
this.IsTabStop = true;
// Set focus on the TextBox.
TB1.Focus();
}
It will spark up the SIP as it enters the <TextBox> ready for input. Hope it's what your looking for.
Got it from this MSDN blog.
The easiest way would probably be with creating your own user control. However it is most likely a lot of work to get it to work as a normal keyboard.
http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Control-The-Basics.aspx
Or maybe perhaps this will help http://www.silverlightshow.net/items/Windows-Phone-7-Creating-Custom-Keyboard.aspx

Programmatically enable a disabled checkbox in a Windows Phone 7 app

I'm writing my first device-specific application which is a Windows Phone 7 panorama app. I'm currently still busy on the UI as I'm playing around with the features then I stumbled upon a problem that I couldn't fix. You see, I have two checkboxes for some sort of login form. One is a "Remember me" and the other a "Sign me in automatically" checkbox. The action I want is that when I uncheck Remember Me, I would like the Sign in Automatically checkbox to be unchecked and disabled. That I was able to do but the reverse always causes an error. I used to write simple PHP web apps and JavaScript so I have some programming knowledge but C# is fairly new to me.
private void RememberMe_Unchecked(object sender, RoutedEventArgs e)
{
AutoSignIn.IsChecked = false;
AutoSignIn.IsEnabled = false;
}
That one works but this one doesn't:
private void RememberMe_Checked(object sender, RoutedEventArgs e)
{
AutoSignIn.IsEnabled = true;
}
The latter throws a "NullReferenceException was unhandled" error.
My XAML code looks like this:
<CheckBox Content="Remember me" Height="71" Name="RememberMe" Unchecked="RememberMe_Unchecked" Checked="RememberMe_Checked" IsEnabled="True" IsChecked="True" />
<CheckBox Content="Sign me in automatically" Height="71" Name="AutoSignIn" IsEnabled="True" IsChecked="True" />
I've done some research and my approach seem to be wrong but I'm not sure how to make it work.
Without the XAML I can't be 100% sure, but make sure you are not setting the IsChecked property programmatically. When you do so, the IsChecked method will get called once before everything is initialised properly on the page. So while the code posted by Matt works:
<CheckBox Name="AutoSignIn" />
<CheckBox Name="RememberMe" Checked="RememberMe_Checked" Unchecked="RememberMe_Unchecked" />
The following won't (because it tries to reference the AutoSignIn box before the page has finished initializing)
<CheckBox Name="AutoSignIn" />
<CheckBox Name="RememberMe" IsChecked="True" Checked="RememberMe_Checked" Unchecked="RememberMe_Unchecked" />
To fix this, you can set the IsChecked property programmatically instead of in XAML, or there might be some other way around this that someone else can point you to.
Your code works for me.
I used your event handlers with the following XAML:
<CheckBox Name="AutoSignIn" />
<CheckBox Name="RememberMe" Checked="RememberMe_Checked" Unchecked="RememberMe_Unchecked" />
Is the error thrown on the line in RememberMe_Checked? or on something else which is set as a consequence of changing the enabled state of AutoSignIn?
Do you, for instance, have any databindings that could be affecting this?

Categories

Resources