navigating to a page class in a library in WP8 - xaml

I have created a page class in the windows phone class library and I referenced that dll in windows phone app project(WP8).
Now how do i navigate to the page class created in the library..How do i specify the uri?
The exact API and syntax would help please.
I have tried using the this.frame.Navigate(typeof(pagename)) as well as the NavigationService.Navigate(new uri("/pagename.xaml",UriKind.relative))..Both of the above are not working..I am assuming there is a mistake in the path specified in the uri..

The following did work for me correctly.
NavigationService.Navigate(new Uri("/AssemblyName;component/MyPage.xaml", UriKind.Relative));
or to generalize the Uri , its format should be : /{assemblyName};component/{pathToResource}
Just be sure you don't have dot"." in your assembly name as it may result in some uri format exception.
Hope this works.

Related

Is it possible to make WebView control to read local html files?

I'm making an application with WebView control. And I want it to read local html file. But I can't find the right way to make it possible.
At first, I simply tried to use Navigate method and provide the file path in the "file:///~" format string as a parameter, but it didn't work.
https://learn.microsoft.com/ja-jp/windows/communitytoolkit/controls/wpf-winforms/webview-known-issues
This Microsoft page says that WebView control does not recognize "file:///~" protocol.
And it shows the 3 solutions to make WebView control to read local html files.
Use NavigateToLocal() method.
Use NavigateToLocalStreamUri() method.
Use NavigateToString() method.
I tried all of them, but each 3 have some issues that doesn't make it work.
NavigateToLocal method requires a RELATIVE path of the file (not the absolute path), relative from the application executable directory. So files in somewhere else from the application directory cannot be read by this method.
NavigateToLocalStreamUri method is not even implemented according to the page! I once tried it anyway, but it returned an exception and didn't work.
NavigateToString method can render the given html content string, but the external files like css, js, image files included by html codes cannot be loaded, so it does not provide a full function.
I found some sample of using NavigateToLocalStreamUri method and tried it by myself.
(VB.NET)
wvwMain.NavigateToLocalStreamUri(uri, New StreamUriResolver())
Public Class StreamUriResolver : Implements IUriToStreamResolver
Public Function UriToStream(uri As Uri) As Stream Implements IUriToStreamResolver.UriToStream
Return New FileStream(uri.LocalPath, FileMode.Open)
End Function
End Class
By this code, NavigateToLocalStreamUri method returns System.Resources.MissingManifestResourceException.
What I want to realize is very simple.
Using WebView control
Read local html file located anywhere on the local storage
And render the html file completely as an expected result
But I don't see the way right now.
I would appreciate your advises or helps.
The method NavigateToLocalStreamUri will not work. Please see https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/webview-known-issues.
You have to use NavigateToLocal, but you will see a warning that it is deprecated. However, it does only work with relative paths. Is it possible for you to restructure your application so that you can use relative paths?
The NavigateToLocal method is the only way that I've found to call local HTML files in Microsoft.Toolkit.Forms.UI.Controls.Web WebView v6.0.
On Visual Studio 2019 Windows 10, the following VB.NET code works on my PC
Imports System.IO
Dim sFileName = Application.StartupPath & "/MyPage.html"
wv.NavigateToString(System.IO.File.ReadAllText(sFileName))
where wv is a WebView object.

XamlParseException when using UserControl from class library dll

I have created a library which has a Popup UserControl similar to the one here.
When I create a fresh Universal Windows App and create the same UserControl inside an app and open the popup, it opens.
But if I create a Class Library and create the same UserControl inside it and try to use it (by opening the popup) inside an app, I get a XamlParseException.
It is as follows -
Windows.UI.Xaml.Markup.XamlParseException occurred
HResult=-2144665590
Message=XAML parsing failed.
Source=Windows
StackTrace:
at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation
componentResourceLocation)
at PopupTestLibrary.MyUserControl1.InitializeComponent()
I am not able to understand exactly why this is happening, since the code works fine when not called from an external class library.
Some Questions I found to be similar to mine, here on SO -
XamlParseException when consuming a Page from a library
Cannot instantiate UserControl from another assembly
All help is appreciated!
You need to Add a Resource Dictionary in your App and Add the Usercontrol Xaml content to it
as Xaml is Considered as a Content file not compiled into the code
I think that this post is just as yours.. :
https://social.msdn.microsoft.com/Forums/en-US/63f071be-a3c5-4f2d-ace2-73ca750e3252/rtm-usercontrol-class-library-and-assembly-name-with-
And, It's known issue:
Dot in the project's name cause XAMLParseException
I hope that this will help you in your issue..

The attachable property HtmlSource was not found in type WebViewExtension

I found this source at Callisto for WebView as WebViewExtension method. This same method was working fine in windows 8.1 apps and now when I try to use in universal windows apps then it is giving me this error.
The attachable property HtmlSource was not found in type
WebViewExtension
I am using this inside a user control with this syntax.
<WebView x:Name="ContentView"
Margin="15,10,10,10"
callisto:WebViewExtension.HtmlSource="{Binding SelectedFeedItem.Content}"/>
Source of WebViewExtension method is here.
Update:
Just to make sure I haven't messed up my xmlns declarations.
1. I have a common folder common and in inside I have a class called Callisto.cs file with the same source copied and no change.
2. In my xmlns: declaration I have xmlns:callisto="Myrssapp.Win10.Common"
Below is the image.
I found my issue and I don't know why it worked in Win 8 or I must have changed something. The mistake was in the xmlns: statement.
instead of
xmlns:callisto="Myrssapp.Win10.Common"
it should be
xmlns:callisto="using:Myrssapp.Win10.Common"
I missed the using keyword.

Windows Phone 8.1 File Picker UnauthorizedAccessException

I have a problem trying to replicate the File Picker example in link, I create a new application using a Universal Application Windows store template.
I extract the content of the class Scenario02 and create a similar one in my example. This class implements an interface called IFileOpenPickerContinuable which I extract from the class ContinuationManager and create a file in my project with the same name to implement that interface.
I don't get any compilation errors when I run the application. When the line openPicker.PickMultipleFilesAndContinue(); is executed, it throw a exception.
'UnauthorizedAccessException'(Access is denied. Exception from HRESULT: 0x80070005) exception.
In the Microsoft example they don't modify any of the manifests of the application. Do you know what can I be missing?
(Question solved in a question edit. Converted to a community wiki answer.)
The OP wrote:
Solved! The problem was trying to launch the data picker in the class constructor.

Unable to get namespace System.Deployment.Application

I am trying to get this: System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun
But the application namespace is not there. I just see System.Deployment.Internal. The object browser, however, shows me all the properties and methods of that namespace, but my app can't see it.
What am I missing?
Did you add a reference to System.Deployment?