C# UWP WebView Not appearing on UWP mainpage - c#

I am working on webview control in C# UWP app. Everything was working. All at a sudden webview stop showing the webpage on the window. I tried creating one more app and rewrite the code once more. But it's not working now.
Below is the code.
<Page
x:Class="hello.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:hello"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid >
<WebView x:Name="webView" Source="http://www.www.bing.com" />
</Grid>
</Page>
ERROR :
I tried using other URLs as well. Tried webView.Navigate(new Uri("http://www.bing.com")); in the cs file as well , but webview is not at all appearing in the window. Searched a lot but did not get any solution.
All break points are getting hit properly and it's not throwing any error while running. Cleaned the debug folder manually and rebuild the app again .. but no luck.
Can someone help me to fix the issue ?

C# UWP WebView Not appearing on UWP mainpage
I checked your code, I found you have passed wrong uri http://www.www.bing.com, and if you want to make the webview fill the Grid you need set VerticalAlignment="Stretch" HorizontalAlignment="Stretch", I edited your code, and it works, please refer the following.
<Grid>
<WebView
x:Name="webView"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Source="http://www.bing.com"
/>
</Grid>
You could call webView.Navigate(new Uri("http://www.bing.com")) method in the page Loaded event, and remove above Source property in xaml code.
private void Page_Loaded(object sender, RoutedEventArgs e)
{
webView.Navigate(new Uri("http://www.bing.com"));
}
Please note your WebView will access internet, so you need check internet capability.

Thanks very much , Internet was the root cause , adding that solved the problem.

Related

On Windows 10 (1803), all applications lost touch or stylus if a WPF transparent window covers on them

If I create a new WPF application with a simple empty window like the code shown below, I find that all applications which are covered by the WPF app lost touch or stylus reaction. This can only be reproduced when Windows 10 is upgraded to 1803 (10.0.17134.0).
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
I wrote another WPF application to find out what happened. So I add a StylusDown event to the Window like the code shown below:
// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}
But the breakpoint never reached until I closed the transparent WPF window which is on top.
I pushed the very simple code to GitHub: dotnet-campus/TouchIssueOnWindows10.0.17134. Cloning it might help a little.
Why does this happen and how to solve it? Any reply is appreciated.
Updated
Microsoft has fixed this issue in .NET Framework August 2018 Preview of Quality Rollup.
August 30, 2018—KB4346783 (OS Build 17134.254)
Addresses an issue where touch and mouse events were handled differently in Windows Presentation Foundation (WPF) applications that have a transparent overlay window.
Original
After a whole week's debugging, I finally find out the solution.
Just add a ResizeMode="NoResize" property for the Window as the code shown below:
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
#lindexi has posted this issue and this solution into his post. If you want more information about this issue, read win10 17025 touch bug - lindexi for more details. (This post is written in multiple languages, so you'll miss nothing even if you ignore the unknown characters.)
Actually, I still can't figure out why this property helps.
Could anyone explain the reason for this issue?

Navigation in Windows Universal Apps 10 Not Working (Taking me to a blank page)

and thank you. I'm using Visual Studio 2015 and trying to navigate between 2 pages, MainPage.xaml and Meds.xaml On MainPage.xaml I put this button to navigate to Meds.xaml with.
<Button x:Name="button_meds" Content="Meds" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="268,405,0,0" FontSize="18.667" Click="button_meds_Click"/>
In the MainPage.xaml.cs file, I simply did this
private void button_meds_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(Meds));
}
Meds.xaml has an image and background, but I omitted the logo and grid from the code below
<Page
x:Class="SQLMobileMoodSwing.Meds"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SQLMobileMoodSwing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
</Page>
I'm not getting any errors, but when I click the button, it simply takes me to a white page. Not sure what I'm doing wrong, have looked for solutions but nothing seems to work.
Thank you!
I have created Meds.xaml as XAML View, not as Blank Page.
Then I deleted it and created again as a Blank Page and BOOM! It works

Run Flash in WPF

i am trying to run a .swf file in my WPF application, i have created a html page and in that i have referenced my .swf file using object tag and then loading that html page in my Main Window
my xaml looks like
<Window x:Class="sirajflash.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WebBrowser Name="myBrowser"></WebBrowser>
<!--<Frame Name="myframe"/>--> //tried with frame also but no luck
</Grid>
</Window>
assigning the source
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
myBrowser.Source = new Uri(CreateAbsolutePathTo("playflash.htm"), UriKind.Absolute);
}
private static string CreateAbsolutePathTo(string mediaFile)
{
return System.IO.Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, mediaFile);
}
}
The Problem:
when i run the application the warning occurs that ActiveX content is trying to access etc etc and when i allow it nothing appears in my main window the warning keeps on occuring multiple times.
if i run the flash movie in the browser directly it runs just fine.
Regards.
I have a flash based clock as a .swf file on my C:\Test\MyClock.swf
I have a htm file at C:\Test\MyHtml.htm
<embed src=C:\Test\MyClock.swf
width=200 height=200
wmode=transparent type=application/x-shockwave-flash>
</embed>
I have web browser control as below...
<Window x:Class="MyFlashApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WebBrowser Source="C:\Test\MyHtml.htm"></WebBrowser>
</Grid>
</Window>
On running the app, I see the webbrowser control giving warning as "To help protect your security, Internet Explorer has restricted this file from showing active content that could access your computer. Click here for options."
I accept the warning by right click and the left click "Allow Blocked Content". A confirmation popup appears to which I say Yes.
I see the Flash based clock.
WebBrowser control can support flash directly . If you don't need to present anything in HTML then you can directly provide the path to the flash file .
myWebBrowser.Source = "C:\Test\MyClock.swf"
However you will still get the IE warning message.

Adding x:Name to a user control gives error in generated code of page its used in

I am basically using a user control for the first time, so hopefully it's just a dumb mistake.
I have a simple user control
<UserControl x:Class="TestProject.WebApp.myUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid>
<sdk:AutoCompleteBox Name="myACB" ItemsSource="{Binding Data}" FilterMode="StartsWith" MinimumPrefixLength="2" >
</sdk:AutoCompleteBox>
</Grid>
</UserControl>
I am using the control in another page (in a stack panel):
<navigation:Page x:Class="TestProject.WebApp.myPageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:TestProject.WebApp"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
<Grid>
<StackPanel Orientation="Horizontal">
<local:myUserControl x:Name="myUC" />
</StackPanel>
</Grid>
</navigation:Page>
The control is in the same namespace as page. Removing the x:Name allows the project to compile and the control functionally works. When x:Name is specified I get an error in the generated code of the page:
Type 'TestProject.WebApp.myUserControl' is not defined.
It happens on these lines of code:
internal TestProject.WebApp.myUserControl myUC;
this.myUC == (TestProject.WebApp.myUserControl)this.FindName("myUC")
I tried with two different controls. Same thing. The generated code has "using TestProject.WebApp;" so I don't know why there is an error only when I have a named instance of the control.
I also cannot seem to use just the Name property. I even tried overloading the NameProperty in the control.
I was able to find a post about this here:
.g.vb file claims that Type X is not defined, even though it is!
Apparently, there is an issue when a project has a service reference (in my case I am using RIA services) and the user control resides in an assembly with the same root namespace as the one you are trying to use it in.
So for me it was,
TestProject.WebApp
Then I tried creating a new project for just the control
TestProject.Controls
Same problem.
Then, when I renamed the project and changed the namespace to
CustomControls
it worked.
Hopefully this saves someone else from some frustration and I really hope this problem can be fixed by MS soon.
What you are showing here should work. What is the default namespace in your project property's? Also did you rename your user control after you created it. Both of those issues could be causing you problems.

Using ICSharpCode.AvalonEdit on .Net 3.5?

I'm trying to use the ICSharpCode.AvalonEdit.TextEditor control from the SharpDevelop 4.0 project in a WPF app that I'm building, but I can't seem to get it to work.
I checked out a copy of the source code from svn://svnmirror.sharpdevelop.net/sharpdevelop/trunk/SharpDevelop/src/Libraries/AvalonEdit at revision 4304. Then, I built the project using Visual Studio 2008 SP1, which succeeded without errors.
I then created a blank new WPF project, added the build DLL to the toolbox and dropped the TextEditor control onto the default empty window, like so:
<Window x:Class="AvalonEditTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Title="Window1" Height="300" Width="300" >
<Grid x:Name="LayoutRoot">
<avalonedit:TextEditor Name="textEditor" />
</Grid>
</Window>
However, when I run the project, the form comes up completely blank. No caret, the mouse cursor stays the default pointer, and the window does not respond to keypresses.
Am I missing something, or is AvalonEdit just a little broken?
[EDIT: I'm starting to think it might be related to my specific setup. I'm running the 64-bit Windows 7 RC. Might that have something to do with it? I've tried building it for x86 only, made no difference.]
Are you sure your namespace declaration is correct?
You can try something like this:
<Window x:Class="Editor.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:e="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit">
<Grid>
<e:TextEditor x:Name="Editor" WordWrap="True" Height="200">
</e:TextEditor>
</Grid>
</Window>
I was able to get it to work without any issues.
The AvalonEdit TextEditor is just a view for a TextDocument model.
The problem was that a new AvalonEdit instance didn't start connected to any model instance, so there wasn't anything to edit.
The reason the code from statictype worked was that he didn't use <avalonedit:TextEditor/>, but <avalonedit:TextEditor></avalonedit:TextEditor>. This will assign an empty string to the Text property, which caused the editor to implicitly create a new document.
But this isn't relevant with recent AvalonEdit versions anymore, the editor will now always create a new TextDocument.
This works for me with the latest build
<DockPanel LastChildFill="True">
<avalonedit:TextEditor
HorizontalAlignment="Stretch"
Name="textEditor1"
VerticalAlignment="Stretch" />
</DockPanel>

Categories

Resources