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
Related
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...
I'm developing an app and I'd like when the user is in Tablet Mode and switches from one app to other to show a black screen when you press "alt + tab" and the opened apps are being shown. I'd like instead of showing the "myTrip" screenshot of the app to show a black screen.
I know for WPF we had ShowInTaskbar = false but nothing like that in Windows 10 Universal App Platform.
I tried so far:
Window.Current.CoreWindow.VisibilityChanged += CoreWindow_VisibilityChanged;
private void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
var parentGrid = RootPanel();
parentGrid.Visibility = e.Visible ? Visibility.Visible : Visibility.Collapsed;
}
But the snapshot image of the app is taken before those events are being called. Any idea on how to do it?
Regards.
I don't get why exactly you want to do this, but here it goes.
You'll need to handle the Activated event of the current thread, and than place a control over your content. See the example bellow.
First, the XAML:
<Canvas Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
<Canvas x:Name="contetProtector" Canvas.ZIndex="10" Background="Black" Width="1014" Height="758" Visibility="Collapsed"/>
<TextBlock Text="My precious content" FontSize="50" Canvas.Top="50" Canvas.Left="50"/>
<TextBlock Text="Nobody should see it" FontSize="50" Canvas.Top="100" Canvas.Left="50"/>
</Canvas>
Then, the codebehind of the page:
public MainPage()
{
this.InitializeComponent();
CoreWindow.GetForCurrentThread().Activated += CoreWindowOnActivated;
}
private void CoreWindowOnActivated(CoreWindow sender, WindowActivatedEventArgs args)
{
if(args.WindowActivationState == CoreWindowActivationState.Deactivated)
this.contetProtector.Visibility = Visibility.Visible;
else
this.contetProtector.Visibility = Visibility.Collapsed;
}
Here you can see the unprotected/active screen, and here the protected one.
Hope it helps.
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
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
In my app there is a canvas with a small image (not taking up entire space of canvas).
when user clicks on image and drags inside the canvas, it traces the path with a black line. Till here everything works. Now, I want the path to be deleted as soon as the user releases the hold on the mouse. I am using MouseLeftButtonUp on the canvas to detect the mouse release. Now problem is this is working randomly. sometimes it fires and sometimes it does not. Kindly help.
XAML:
<Canvas Height="400" HorizontalAlignment="Center" Margin="10,10,0,0" Name="canvas1" VerticalAlignment="Center" Background="Aqua" Width="400">
<Image Canvas.ZIndex="30" Canvas.Left="10" Canvas.Top="10" Height="20" Name="dot1" Stretch="Uniform" Width="20" Source="/BoxIt;component/Images/dot.png" MouseLeftButtonDown="dot_MouseLeftButtonDown" />
</Canvas>
C#:
this.canvas1.MouseMove += new MouseEventHandler(canvas1_MouseMove);
this.canvas1.MouseLeftButtonUp += new MouseButtonEventHandler(canvas1_MouseLeftButtonUp);
Eventhandler in C# :
void canvas1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// code to delete the path
}
In Windows Phone we are advised to use the Tap, Hold and Manipulation* methods instead of the Mouse related events.
Please read this for more information.