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...
Related
I am new to XAML and Xamarin and want to build a test app on my android device. On the first page there's a button that directs to an other page. Here's a piece of the C# code HomePage.xaml.cs:
public void Clicked(object sender, EventArgs ea)
{
Navigation.PushModalAsync (new SecondPage ());
}
On the second page I want to load an image and a button, but as soon as I include the button, I get this exception when running the app: java.lang.reflect.InvocationTargetException. Without the button, everything works fine. Here is the xaml code of the image and the button of the second page:
<Image Source = "image.png"
x:Name="image"
VerticalOptions="Start">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="ImageTapped"/>
</Image.GestureRecognizers>
</Image>
<Button Text="Text"
BackgroundColor="Aqua"
TextColor="White"
VerticalOptions="EndAndExpand"/>
And here the C# code of the "ImageTapped" function:
public void ImageTapped(object sender, EventArgs ea)
{
image.IsVisible = false;
}
I have no idea what I am doing wrong and I would really appreciate it if somebody could me!
I just solved it by using a <StackLayout></StackLayout>, before I used the <ContentPage.Content>.
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 new to c# and wp development.
On "Holding" I want the Content value of the button as a string in my c# code.
<Grid>
<Pivot>
<PivotItem>
<Grid>
<Button x:Name="Venue1" Content="Venue1" HorizontalAlignment="Left" Margin="30,0,0,0"VerticalAlignment="Top" Width="342" Height="102" Grid.Row="1" Holding="Holding"/>
</Grid>
</PivotItem>
</Pivot>
</Grid>
I thought it was pretty straightforward and did this but doesn't work.
TextToSpeech is a method that takes a string and reads it out. It reads out "Windows.UI.Xaml.Controls.Grid"... why?
private async void Holding(object sender, HoldingRoutedEventArgs)
{
await TextToSpeech(this.Content.ToString());
}
Try this :-
private async void Holding(object sender, HoldingRoutedEventArgs)
{
var obj = sender as Button;
var content = obj.Content;
await TextToSpeech(content);
}
What are you doing wrong is by using this. Here this does not belong to button but for the page itself. In place of this you have to use the corresponding button object that i have already shown how to use.
For further reference see This Keyword
you can also use name of the button to get its content that is little bit hard coded.
It is pretty straightforward :)
await TextToSpeech(this.Venue1.Content.ToString());
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
I have the following button on my page:
<AppBarButton Grid.Column="0" x:Name="backButton" Icon="Back" Margin="10,26,0,-1"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
IsEnabled="True"
Visibility="Visible"
Foreground="Green"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" Grid.Row="1" Grid.RowSpan="2" VerticalAlignment="Stretch"
/>
The button appears but clicking it does nothing. This was placed on the second of two pages in the application. I followed the instructions in NavigatonHelper.cs to get it wired up to my second page, but haven't done anything special in the first. What am I missing?
I even tried tying the Click property to a custom function:
public void ClickGoBack(object sender, RoutedEventArgs routedEventArgs) {
this.Frame.Navigate(typeof(HubPage));
}
But this never even got hit when I clicked the button.
Have you checked the Click existed in AppBarButton defined?
like: <AppBarButton ... Click="ClickGoBack"></AppBarButton>
and you should use
if (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
instead of
this.Frame.Navigate(typeof(HubPage));
You could do this instead much more easier for me.
<AppBar><Button Style="{StaticResource BackButtonStyle}" Click="Click1"></Button>
</AppBar>
and for your code behind...
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Frame.GoBack();
}
Something was put after the top grid in the XAML that overlapped the button - I didn't understand the concept of "natural order" until now. Thanks for the help everyone!