Today I’ve been solving interesting task. All my investigation I’ll write on this article. A problem is following: there is a regular C# application which should display all installed WinRT application per user.
There is a whole section of all WinRT APIs for Windows 8 that are able to be called from a regular C# application on MSDN. This one includes a PackageManager class which allows getting all installed packages.
Access WinRT API from Console application.
First step, create a usual Console application.
Then we need reference a Window.dll. However, in the desktop projects Windows tab doesn’t appear by default. For this we need manually add following lines to csproj file.
After that step a new tab will appear:
Now we can try to get all WinRT installed packages. However, when we build that we will have following error:
The type ‘System.Collections.Generic.IEnumerable`1<T0>’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.
Unfortunately this assembly doesn’t present on reference tab. For this you need add this assembly from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5 folder.
Get all installed WinRT application per user.
We will get installed Metro/Modern packages per user because on same computer different users can install different applications. All this information is available by PackageManager class.
var packageManager = new PackageManager(); var metroApps = packageManager.FindPackagesForUser(WindowsIdentity.GetCurrent().User.Value);
That’s all and really simple, isn’t it? 😉
In this article I’ll explain one way how to hide a cursor after n-seconds of inactivity though WPF behavior mechanism. Same effect you can observe on almost any video player — if you don’t touch a mouse for the few seconds, cursor will disappear.
First of all, what is a behavior?
A behavior encapsulates pieces of functionality into a reusable component, which we later on can attach to an element in a view. Emphasis is on reusable. Behaviors also have the benefit of keeping the MVVM pattern intact, since we can move code from code behind to behaviors. You can find a good introduction on the behaviors, type of behaviors in a great article of Robert Hedgate.
Implementation though attached behavior.
Advantage of attached behavior is that it can be used in a native windows store app. Disadvantage is that it does not show up in Blend under behaviors, and thus cannot be attached if you are using Blend. In my case it’s very important to have possibility of using it on windows store app.
In the implementation of the behavior we have 4 dependency properties:
- Interval — time interval after which cursor should be hided.
- IsEnabled — enable or disable behavior functionality.
- ActiveCursor — cursor type when it’s not active.
- InactiveCursor — cursor type when it’s active.
Logic isn’t really complicated so you just can download it from my Bitbucket.