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();
}
Related
Is UI automation available for the main menu of the Apple TV and not a specific application? I already setup the whole UI testing thing using XCode and tried using the remote control but it is only available for the application that was defined using XCUIApplication.
So is it possible to control the whole system rather than a specific application? I was thinking of something similar to pyatv but using XCode since I might be able to get more information concerning the current focused apps and so on.
There is an API XCUIApplication(bundleIdentifier: ) to interact with not-AUT apps. You need to substitute the right identifier for this Springboard-like interface. Maybe it is a Headboard, but I'm not sure.
Bundle identifiers of tvOS apps https://github.com/rzakhar/XCTApps/blob/master/Sources/XCTApps/tvOS.swift
I have built a UWP app, and a WPF app within the same solution. I am using the FullTrustProcessLauncher class to launch the WPF app from the UWP app. I am also using the AppServiceConnection class to allow the two apps to communicate with each other. This all works fine in a basic scenario. But once I start really developing my WPF app beyond the samples I can find I will need to start debugging in visual studio.
I've tried the following:
Set breakpoints within the WPF code.
Result: I did not expect this to work, and it did not.
Attach to the running WPF process once the UWP launches it.
Result: The "attach" button when the running WPF process is selected is grayed out.
I started investigating the new VS extension "Desktop Bridge Debugging Project" and followed along with samples and documentation.
Result: All of the samples I could find seemed to revolve around converting an existing WPF app to UWP. Because of this, I don't think this is a solution. I could be wrong...
Below is the relevant code for launching my WPF app from the UWP app:
int messageNumber;
private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (this.messageNumber == 0)
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
this.messageNumber++;
await AppServiceManager.SendMessageAsync(
$"Message number {this.messageNumber}");
}
As I mentioned above, for now i'm just following the Microsoft examples. I would eventually like to add more complex code and be able to debug.
How else can I get debugging features for the WPF app launched from a UWP app?
Thanks
In order to debug the fulltrust process in your UWP project, you will have to start the UWP process without debugging (or detach the debugger from it). Then attach to the debugger to the fulltrust process and your breakpoints will be hit.
I realize this is not an ideal workflow, and we are working on improving this in a future update for VS.
Advanced Installer (a MSFT partner) provides now an extension for Visual Studio 2015 and 2017 that can build an AppX (along with your MSI/EXE) package from a single project and also enables debugging for your application with a few clicks - much simpler than current solutions.
- watch video demo -
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.
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.
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?