How to test auto-launch on Windows Phone 8.1 Emulator - silverlight

I am new to Windows Phone app development and currently writing a Silverlight app for Windows 8.1.
I was able to follow the Microsoft instruction to have my app associating a particular file extension.
Now a rather stupid question, how do I test this functionality in the Emulator ?
Let's say I have a associated file on the "SD card", how would I browse to that file and open it. Or is that completely unnecessary and I am overthinking that feature?
Based on arya404's answer I added a test button to my app which launches a local file.
Button itself:
<Button x:Name="button" Content="Test" Click="test_button_clicked"/>
The button's code:
private async void test_button_clicked(object sender, RoutedEventArgs e)
{
StorageFile myFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("local.file");
await Windows.System.Launcher.LaunchFileAsync(myFile);
}

Have you tried to open the file through the Files application ?
https://www.microsoft.com/en-us/store/apps/files/9wzdncrfj3pl

Related

Unsupported operation on Windows Phone for FontImage.createMaterial()

I'm using the following code to set the back command on the Toolbar in a Form:
Command back = new Command("Back") {
public void actionPerformed(ActionEvent ev) {
mainForm.showBack();
}
};
Style s = UIManager.getInstance().getComponentStyle("Title"); // getTitleStyle();
FontImage backIcon = FontImage.createMaterial(FontImage.MATERIAL_ARROW_BACK, s);
this.getToolbar().addCommandToLeftBar("", backIcon, back);
This works fine on iOS and Android, but on Windows Phone (Eumlator) I get java.lang.RuntimeException: Unsupported operation. After doing some debugging in the C# code, I found that the Exception is thrown in Font.derive() that calls CodenameOneImplementation.deriveTrueTypeFont(), which is aparently not implemented on Windows Phone.
Are Material icons simply not supported on the current Windows Phone port, or is there a workaroung for this? Or am I doing something wrong?
The old Windows Phone port doesn't support a great deal of functionality including icon fonts.
We are working on a completely new ground up port that should support everything.
Notice that icon fonts do work in the JavaScript port and you should be able to deploy that everywhere.

Debugging JavaScript in Chromium Embedded Framework

I have a WPF application which uses CEF to display web content. My question is, is there a way to debug the Javascript/Web parts inside a WPF application?
You may also use ShowDevTools() extension method (source)
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.ShowDevTools(); // Opens Chrome Developer tools window
Enable remote debugging in your application:
C# (CefSharp)
CefSettings.RemoteDebuggingPort = 8088;
C++
CefSettings settings;
settings.remote_debugging_port = 8088;
then run your app and point your browser to http://localhost:8088/ to access the Chromium developer console (the same you have in Chrome with Ctrl+Shift+j)
While the accepted answer is correct, it doesn't really have enough detail.
I got this working in CefSharp using the WinForms control in a WPF application. (the WinForms control seems to have better performance). The code for remote debugging will probably be very similar for the WPF control though.
var settings = new CefSettings { RemoteDebuggingPort = 8088 };
Cef.Initialize(settings);
WindowsFormsHost.Child = new ChromiumWebBrowser(url);
Then go to http://localhost:8088/ in your browser.
To use 'ShowDevTools()' you will need first verify if the browser is initialized.
An example solution:
//Add an event to check
ChromeBrowser.IsBrowserInitializedChanged += ChromeBrowser_IsBrowserInitializedChanged;
//Declare the event method to be called
private void ChromeBrowser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (e.IsBrowserInitialized)
{
ChromeBrowser.ShowDevTools();
}
}
To open the Chromium Dev-Tools window you can do the following:
CefBrowser.GetBrowser().GetHost().ShowDevTools();
This is similar to Eido95's answer, but it doesn't require the extension methods, which essentially just wrap these method calls.
NOTE: The control needs to be initialized before calling this method can be called. If you're wiring-up and F12-like functionality this shouldn't be a problem. If you're trying to do this when the app is starting you will need to listen for the ChromiumWebBrowser.IsBrowserInitializedChanged event
An alternative can be to launch cef with --enable-chrome-runtime.
You'll have the fully featured debugger (link files on disk and edit them from the debugger)

Silverlight 4: Read in file from local system without being OOB?

Any tips/tricks on how to read a file from the local system dynamically in silverlight 4 without having to be out of browser?
Impersonation? Toggling app elevated trust on/off programmatically?
Or is this simply impossible to do without being out of browser?
As it stands I have a Pegasus ImageGear PDF viewer that I feed a "LoadDocument" method a stream of a PDF file.
This of course works fine if the file is an application resource and compiled with the application.
StreamResourceInfo resource = Application.GetResourceStream(new Uri("/TestRIA;component/SampleData/test.pdf", UriKind.Relative));
docViewer.LoadDocument(resource.Stream);
This silverlight application will be hosted through a website deployed on a server. This server has a partition specifically for repositories of files. These files in the "D:" partition are currently accessed by an ASPX web application and displayed in a PDF viewer. We're moving to silverlight, so as the user selects the grid row representation of that file in the repository, I know the "NAME" of the file. The repository's location is a string held in the database configured in another application. I simply concatenate the file name to that repository path and have the filepath.
Again, the 3rd party viewer's "LoadDocument" method has two overloads. One that accepts a stream of the PDF and one that accepts the filename of the PDF.
For example I have a click event that feeds the name of the document, and I already have the root path to concatenate it to:
void testButton_Click(object sender, EventArgs e)
{
string docName = myListBox.SelectedItem.Content.ToString();
docViewer.LoadDocument(repositoryPath + docName);
//OR using stream
Stream s = new FileStream(repositoryPath + docName, FileMode.Open);
docViewer.LoadDocument(s);
}
You cannot programatically interact with an arbitrary file in SL4. Period. There's your section of isolated storage you can read from and write to files, but that isn't what you're looking for. You can read and write files through the file open dialog, but again I think that's not what you want.
The only way out of the Silverlight sandbox is the network. You have to have to talk to a non-sandboxed service to do this. SL has OK support for Web Services, Http, and even sockets. This seems doable for you since you're talking about the file being somewhere on a "server".
I remember reading that this will work without elevated trust only if the code is initiated with a user action such as button click.
http://msdn.microsoft.com/en-us/library/ff382752%28v=vs.95%29.aspx
For security purposes, if a Silverlight application is a sandboxed
application, file and print dialog boxes must be user-initiated. This
means you must show them from a user-initiated action, such as the
click event handler for a button.
As a possible workaround, if your Silverlight app is backed by a service, you could make the reading/writing of the file be handled by the service, assuming it has access to the location(s) and sufficient rights in the destination folder(s).
Create an OpenFileDialog box and you can return stream(s) to the selected file(s).

How can I get a Silverlight application to check for an update and ask user to upgrade?

I have made an out-of-browser silverlight application which I want to automatically update every time there is a new .xap file uploaded to the server.
When the user right-clicks the application and clicks on Updates, the default is set to "Check for updates, but let me choose whether to download and install them":
(source: deviantsart.com)
This leads me to believe that it is possible to make my Silverlight application automatically detect if there is a new .xap file present on the server, and if there is, the Silverlight client will automatically ask the user if he would like to install it.
This however is not the case. I upload a new .xap file and the Silverlight application does nothing.
Even if I add this to my App.xaml.cs:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
}
}
and update the .xap file, the Silverlight application does nothing.
This information enabled me to check if there is an update and if so, tell the user to restart the application, but when he restarts the application, nothing happens:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
}
}
void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable)
{
MessageBox.Show("An application update has been downloaded. " +
"Restart the application to run the new version.");
}
else if (e.Error != null &&
e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, " +
"but it requires a new version of Silverlight. " +
"Visit the application home page to upgrade.");
}
else
{
//no new version available
}
}
How do I make my Silverlight application check, each time it starts, if there is a new .xap file, and if there is, pass control to the Silverlight client to ask the user if he wants to download it, as the above dialogue implies is possible?
The first dialog is about how updates to Silverlight itself are installed and has nothing to do with your application.
Using the CheckAndDownloadUpdateAsync the new XAP should be downloaded automatically. Acording to the doc there is no way to prevent the new version from being installed one you call CheckAndDownloadUpdateAsync.
The screen you are refering to the is not specific to any silverlight application. Its refering to the silverlight plugin itself.
The CheckAndDownloadUpdateAsync method should have downloaded the newer version but the user will need to restart the application in order to start using the new application. You use the UpdateAvailable property of the event args in the completed event to determine whether to ask the user to restart.
You might get what you're wanting by incorporating an external version control check. have it look to see if the version that's installed and the version on the server is different.
If it's different ask the user if they want to update. If they choose yes, then invoke CheckAndDownloadUpdateAsync();
otherwise skip it if they choose no or if the version is the same.
there are many ways to do your own versioning checks. Including static readonly properties that are populated # build time and have some kind of similar result on an http request.
You could use the webclient to grab a response from the server and compare that with the currently loaded version of the application.
You can incorporate a method on the callback to go to show a message that tells the user to restart the app.

Navigation xBap problem with frames

I have a problem in navigation in xBap
I created two pages (Page1 and Page2)
Page1 have one button for navigation to Page 2
<Button Height="23" Width="76" Name="button1" Click="button1_Click">Page2</Button>
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService n = NavigationService.GetNavigationService(sender as Button);
n.Navigate(new Uri("Page2.xaml", UriKind.Relative));
}
in Page2 there is a frame without any source
<Frame Margin="0,90,0,0"/>
After running application, and navigating to page2, the navigation will work normally,
but when I press Go Back in browser, then press button1 again
The browser will show this message
image
Note: in some cases you need to repeat trying
Any help !!
thanks in advance
since your Browser crashes, i suggest this is some bug in one of the following Components:
Browser (IE in this Case)
XBAP Addon/Plugin (yes, there is some kind of plugin which is installed silently within browsers on .NET Framework installation)
I bet, this cannot be solved programmatically... I'd suggest the following:
try to reproduce in different environment (different IE Version, OS etc.)
reinstall .NET Framework and ensure you have the latest, stable final version
do same with Internet Explorer
Firefox has XBAP support as well - try in firefox
If it works in other environments, your users should have no problems with this setup.
Hope this helps,
Best regards
Thomas

Resources