Is there a way to link apps in UWP? - c#

At the moment I am creating an app to simulate simple mechanical motion in UWP. Instead of creating them all in one blank app I have created multiple different apps for the different types of simulation, eg: single particle, connected particles, pulleys etc... I was wondering if there was a way in which I could have a menu and then when a specific button is clicked the app associated with that button is opened, for example:
private void OpenSingleParticle_Click(object sender, RoutedEventArgs e)
{
//open single particle app
}
Thanks for any help that you can offer
Matt

You need to register app to handle custom URI, then you can call this app using launch app from uri. Take a look at msdn articles:
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-uri-activation
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-app-with-uri
Moreover you can even launch other apps for result as it's possible in Android.

Related

How to make a windows service that has a task tray icon for managing it? [duplicate]

This question already has answers here:
How can I display a system tray icon for C# window service.?
(2 answers)
Closed 4 years ago.
I'm familiar with writing windows service applications. I've written a few using various approaches - third party libs, the .NET-provided approach, etc. None of my prior service applications had any way to interact with them, though.
I'm needing now to write a windows service application, but it will need a task tray icon that perhaps brings up a "management GUI" when you click on it.
What is the appropriate pattern for doing this?
Should the service be its own application, but is able to be interacted with through external means - perhaps a database that it polls for config changes? Should it use IPC or something?
Is there a way to make a windows service also have a GUI so that the management GUI and the service are all just the same application?
Is there a way to make a windows service also have a GUI
No; a windows service doesn't have an (interactive) desktop by definition. Anything that points to getting that to work will be a very dirty hack at the very best.
Is there a way to make a windows service also have a GUI so that the management GUI and the service are all just the same application?
You can share code by putting common stuff in a library or something. You can even share the entire codebase and run the application with an --service commandline argument (for example) and the GUI part without (or with --gui) argument(s).
interacted with through external means - perhaps a database that it polls for config changes?
That is a possibility but not the fastest or most efficient
Should it use IPC or something?
I would opt for that. You can use whatever you want; a REST API, WCF, TCP/UDP connections, sockets, (named) pipes, memory mapped I/O... whatever you choose, it will be some sort of IPC. You can even send custom commands to your service but that is very, very limited.
If it were up to my I'd implement it using WCF. But I'm kinda biased, I do lots of WCF stuff.
Summary
Yes, your Windows service can have a GUI. However, that GUI has to be a separate project (say a Windows Forms project). It's just that the Windows Forms project and your Windows service project have to use whatever is common in between such as database, APIs (e.g. WCF), library, etc. Typically, you would carry out the necessary functionality inside your Windows service and update state / settings in your Windows Forms application.
Adding Your GUI to Task Tray along with a Shortcut Menu
In the Main method of your Windows Forms application, create an object of the NotifyIcon class. You can also create a ContextMenu object and assign it to the ContextMenu property of the NotifyIcon object to allow the tray icon to have shortcut menu. Here is a sample:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var icon = new NotifyIcon())
{
icon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
var contextMenu = new ContextMenu();
var mnuProperties = new MenuItem()
{
Text = "Properties"
};
var mnuQuit = new MenuItem()
{
Text = "Quit"
};
mnuProperties.Click += mnuProperties_Click;
mnuQuit.Click += mnuQuit_Click;
contextMenu.MenuItems.Add(mnuProperties);
contextMenu.MenuItems.Add(mnuQuit);
icon.ContextMenu = contextMenu;
icon.Visible = true;
Application.Run();
}
}
private static void mnuQuit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private static void mnuProperties_Click(object sender, EventArgs e)
{
var propertiesForm = new PropertiesForm();
propertiesForm.Show();
}
Needless to mention, you can add as many menu items to the context menu, add forms, etc.
One last point, it doesn't have to be a Windows Forms application. It can very well be a WPF application instead.

Catch a link click with a certain pattern in Windows Runtime

I am developing an app based on a mobile website which runs inside a Windows Runtime WebView for Windows Phone 8.1. Currently, I am looking for a way to catch link clicks in the app's webview which start with a certain pattern. In the Windows Phone Silverlight version, the following was possible:
In my webview I display links like this
Do something in the app
Do something different in the app
In the app, I catch a click on such a link with the following code
MyWebView.Navigating += HandleOwnStuff;
void HandleOwnStuff(object sender, NavigatingEventArgs e) {
String url = e.Uri.ToString();
if(url.StartsWith("ownstuff:")) {
// check which function has been called and do something in the app, e.g. open the camera
}
}
Unfortunately, this approach is not possible in a WinRT app any more. Whenever I click such a link, the launcher opens with the message "Search for an app in the store".
The "NavigationCompleted" handler of the WebView is not called - this link click is catched before any handler of the WebView is called.
An approach which would work is using the UnsupportedUriSchemeIdentified handler, which - unfortunately - is only available starting from Windows 10 in UWP.
Another solution would be to completely rewrite my website so that the ScriptNotify handler can be invoked - which would be way too much work, since the website now also runs in normal browsers, Android and iOS devices - so this approach is definitely not worth the trouble.
Does anyone know a solution? Thanks.
I have talked about this with MSFT for awhile. Your right, with win10 that's why that event was added. The best way to workaround it is to change the website.

Remove share screenshot option - DataTransferManager

In windows 8.1 apps, while invoking the share UI using
Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
we get an option to share the screenshot of the current app by default. Is there a way to remove this feature?
The data I am passing from the app to be shared is a URL.
private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
args.Request.Data.SetWebLink(new Uri(myUrl));
}
When the share pane appears, user is presented with an option to share the screen shot also. The scenario is explained in this link
I tried setting ApplicationView.IsScreenCaptureEnabled to false. It still listed "share screenshot". But when tried to share, shared an empty black screen. Can I do something to remove that option from share pane?
No, all the apps that I know of, have this option listed, so I would say this is a system built-in option, that you cannot remove in your app code.

How to close a Windows Phone 8.1 app

In WP7 and WP8 I just needed to clear the backstack in a page, then press Back button and the app is closed. In WP8.1 I do Frame.BackStack.Clear(), press Back and the app just minimizes.. How to kill it with Back button?
You can add, in your main page definition:
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
Then
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
if (!e.Handled && Frame.CurrentSourcePageType.FullName == "YourApp.MainPage")
Application.Current.Exit();
}
Warning: As others said, you should not use this and let the system handle the app closure. For example, if you use the Application Insights, I found that they are not sent to Azure when in Release mode
I think the above has been depreceated. Exit is now an event.
Try
Application.Current.Terminate();
you can simply create a button by using XAML and then add this code into your Main page xaml.cs
Application.Current.Exit();
MSDN recommends to not close apps in Windows 8.1:
We recommend that apps not close themselves programmatically unless
absolutely necessary. For example, if an app detects a memory leak, it
can close itself to ensure the security of the user's personal data.
When you close an app programmatically, the system treats this as an
app crash.
https://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#close

How to make shortcuts to existing apps (WP7)

I'm developing an app that shows the time, local weather and stuff like that..
The problem I have.. is I can't for the life of me find a way to create a shorcut to apps..
I'm trying to make shortcuts to launch existing apss like calculator, marketplace, whatsapp, etc.
Is this possible using button like:
private void button1_Click(object sender, RoutedEventArgs e)
{
}
and add content inside the brackets..??
I'm sort of a newbie so don't go all crazy on me.. :-)
Sorry to say, but this generally isn't going to be possible under the current (and probably future) versions of the OS. Apps run in a sandboxed environment, and aren't supposed to have access to those kind of things.
You can launch to some of the inbuilt tasks, such as Marketplace:
MarketplaceSearchTask marketplaceSearchTask = new MarketplaceSearchTask();
marketplaceSearchTask.SearchTerms = "games";
marketplaceSearchTask.Show();
But the number of tasks available are very limited.

Categories