How to incorporate Win UI with Prism across the Uno platform? - prism

I fetched the Prism Blank App (Uno Platform) template to set up a basic PrismApplication in the shared project. Probably a very good reason, it is a blank template, therefore even the Win UI Desktop project is missing from the solution. By default this template employs the UWP API instead of the Win UI one as the Microsoft.UI.Xaml namespace. I tried to create another solution with the Win UI specific Uno Platform template but in that case I failed to swap Application with PrismApplication.
Which template do you recommend to kick off, the first or the latter?
Created Win UI & Wasm heads
$dotnet new unoapp-winui -o "Weather.History" -uwp=false -ios=false -android=false -macos=false -sw=false -sg=false
Swapped the base class

Related

Building a Tray Application using Xamarin?

Using .NET Core and Xamarin I thought about building an application that would run on both Windows and macOS environments.
The .NET Core part would be used for all backend stuff and provide its functionality as a REST API. .NET Core however, does not have any support for building native UI applications (WPF, ...) so that's a no-go for building a tray application.
So I thought about using Xamarin for this. But I can't seem to figure out if this is at all possible. Nor can I find any leads on how to get started.
Some alternatives I've not yet further investigated:
Mono, but that doesn't have any integration with VS2017 so that's out...
QT, but that's aimed at C++, so that's out as well
Java, but then why bother using .NET Core in the first place...
Electron.js
For Windows, Xamarin.Forms will not officially support WPF till 3.0.
re: https://blog.xamarin.com/glimpse-future-xamarin-forms-3-0/
In terms of a Tray app, that is native Windows code and would not be a part of Xamarin.Forms UI code, but the native Windows code that would show/hide your app's UI (assumably Xamarin.Forms based)
For macOS, Xamarin.Forms is supported via Xamarin.Mac, and is currently in a "preview" release.
As far as the equivalent of a tool tray app on macOS, in Xamarin.Mac you can create a item (icon and/or text based) in the system status bar.
Typically this is done in the NSApplicationDelegate.DidFinishLaunching and is easy as:
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Variable);
statusItem.Button.Image = new NSImage("moviemadness_icon_dark.png")
{
Template = true
};
statusItem.Button.Action = new Selector("StatusItemButtonAction:");
In this example, any time the icon/text in the status is tapped, the StatusItemButtonAction method is triggered and it either terminates itself if you were holding the control key down at the same time, otherwise it runs the StatusBarPopOver which in my case constructs a NSPopover and shows an embedded Xamarin.Forms TabbedPage UI that shows the mobile app server status, current users of the app, the app analytics, etc...
[Action("StatusItemButtonAction:")]
public void StatusItemButtonAction(NSStatusBarButton sender)
{
var currentEvent = NSApplication.SharedApplication.CurrentEvent;
if (currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.AlternateKeyMask) ||
currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.ControlKeyMask))
NSApplication.SharedApplication.Terminate(this);
else
StatusBarPopOver();
}

How can Xamarin be used to wrap a web app as if it were a native app for Android?

Say I build a super mobile friendly web application that I want in the Play Store for Android users to be able to download.
Could I use Xamarin to:
Wrap the entire mobile app as a single WebView
Register for mobile push notifications
Essentially shortlining an MVP of an android app by using an existing web app? If so, is there any well-known process or documentation that demonstrates this?
Probably the best approach for you would be using Xamarin Forms with one or more pages containing only web views.
I don't love Xamarin Forms because usually for me Xamarin Android+iOS gives a better result in similar time, but your app would be so simple that doesn't make sense to do it with Xamarin Android.
Make sure that your web app will show only what makes sense to be shown in your app, otherwise you risk to see double header/footer, useless buttons... but if the website is yours adding a few parameters to change a bit the UI won't be a problem I guess.
Have a look at this example:
https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithWebview
Another approach is the use of Razor to build your pages in html directly inside your app, but if I understood well it's not what you need:
https://developer.xamarin.com/guides/cross-platform/advanced/razor_html_templates/
Although it is technically possible to do this as the previous answer has suggested. I would recommended firstly reviewing, the relevant stores guidelines on submissions. Apple for example will not allow a submission to their store of any application that simply mirrors the functionality of a website. I suspect Google's would likely be the same.
However that said, to answer your question, Xamarin.Forms would be appropriate for a simple application like the one you are suggesting. Or if you prefer to build to a specific OS, then in iOS with Xamarin you would use the Safari View Controller that was added in it's xcode 8.1 release. Android uses something similar as does windows.
EDIT:
You can use the Web View control in Xamarins Andorid native PCL project to encapsulate your mobile friendly website within an application here is the documentation:
Xamarin Android Developer link to Android Web View
As for push notifications, yes this is perfectly possible using Xamarin.Android. and varies on implementation depending on what you want to use as the back end to handle them, I.E. Azure's notification hub etc.

Does Xamarin support to develop apps for Windows surface and how well?

I want to develop an app for Windows surface tablet and iOS mobile and iPad.
As I am a new user to Xamarin, when I created my first project,it shows 3 projects:-
hello.driod, hello.ios and hello.winPhone.
I have 3 questions based on this:-
How will I be able to write the same code and share for windows 8.1 and iOS?
and whenever I drag and drop the elements to the UI page, will the same elements be copied to both windows and iOS simultaneously or I got to add them seperately?
Currently I dont have a MAC to connect to my PC. Can I write the code and and there while testing it, connect it to a MAC or should it be connected during the whole process?
Please Help!
Using the same code depends on how your structure your app.
You can go the native route where you can share the bulk of your logic by containing it in a shared / PCL project (more on that here), but have platform specific code for your UI.
For example, if you have a cross platform app targeting iOS and Android you would still create the UI in a storyboard for iOS and AXML files for Android. Any code you want to "connect" to your UI would be specific to that platform as you would use the platform APIs. Any code that is not platform specific (i.e., not calling iOS or Android APIs) can go in your shared / PCL project.
Or you can choose Xamarin.Forms which adds a layer of abstraction by allowing you to write the UI in XAML once and have it work on all platforms. The advantage is increased code sharing as now your UI is also shared. The downside is to utilise platform specific features you'll need to implement DependencyService or custom renderers. Read more about Xamarin.Forms here.
As above, it depends. If you are going the native route, then no. If you are going with Xamarin.Forms, then you are using the same XAML code for the UI across platforms, but there is no drag and drop designer.
To build an iOS app you need to be connected to a Mac. You will also need to be connected to a Mac to use the iOS Designer.

Xamarin.Forms on Windows not loading styles from App.Xaml

We have a Xamarin based app targeting iOS, Android, and Windows (not WinPhone but Windows 8.1 as a desktop app for now).
The app utilizes a few PCL's for the vast majority of all views and view models and reusable functionality. The three platform specific projects have very little custom code and, when necessary, inject in custom platform specific services. One of the PCL's also has an App.Xaml that provides the basic styles for the overall app.
The iOS and Android apps load this App.Xaml fine and honor all styles. The Windows implementation of Xamarin.Forms does not appear to load or honor the styles in the same way and our core UI appears blank.
This isn't an issue of the styles just "don't look right" on Windows compared to the other platform but more an issue of everything is invisible. We can click buttons and move around if we know where they would be in the overall UI but we don't see them. Not even an outline.
Not sure what other implementation info I can provide but I'm wondering if anyone else has had issues with Xamarin.Forms on windows and styles?

How can Windows Sidebar Gadget communicate with my desktop app?

I've got a .NET 2.0 Windows desktop application (time-sheets) which i develop and wanted to add a Gadget interface to it (so that app runs hidden and is controlled via the gadget).
What is the easiest way to get my gadget to communicate to my app?
An idea that i had was to have a built-in web server inside the app, and the gadget controls communicates with the app using ajax. However i'm hoping there's a simpler solution.
You didn't specify what technology the gadget and app were written with, so it's hard to answer. Assuming you can use .NET, WCF with a named-pipes binding would be very simple. Just a few lines of code to set it up.
We use win32 APIs in one of our gadgets' ActiveX control to communicate with other instances of the same gadget. Unfortunately, I can't give you the code (because I don't have permission and I don't write the .net stuff) but it boils down to using a window (in your case the application window) as a server and the gadget ActiveX control as the client and use the SendMessage function.
You can see an example of using COM interop with windows desktop gadgets at http://www.codeproject.com/KB/gadgets/GadgetInterop.aspx
NB: make sure the interop assembly is in the application's directory and NOT the gadget directory, otherwise you'll run into problems when updating/uninstalling the gadget.

Resources