Posts

Let me say this – ReSharper is a wonderful and almost indespesable tool for C# development. The improved IntelliSense features and automatic using statements are themselves worth having it installed. But sometimes it stops playing well with Visual Studio keyboard shortcuts. Quite often shortcuts like Ctrl + F (Quick Find) shortcut stop working when Resharper is first installed on a PC with non-US default keyboard.

Some keyboards require different ways to write things like braces and similar. For example on the default Czech keyboard, you have to press Alt Gr + F to write the left square bracket ( ‘[‘ ). Somehow, Resharper for some accidental reason assigns the command it uses for containing declaration (which is normally written as Ctrl + [) to Ctrl + F leaving out the Alt Gr modifier. This way the shortcuts using these unusual characters get broken.

When you find yourself in such a situation, you can luckily fix it quite easily! First change your Windows keyboard layout to US. Then open Visual Studio and opent the Options dialog via the Tools menu. From the left hand pane select Keyboard. Here select the keyboard mapping scheme you prefer (usually ‘(Default)’) and click the Reset button, confirm with Yes and close the options dialog by clicking OK.

Now you probably want to also recover some of the useful ReSharper keyboard shortcuts (no one with ReSharper installed could just live without the all-mighty Alt + Enter shortcut!). You can do just that by going to the ReSharper menu, choosing Options, navigating to Keyboard & Menus and then simply select your preferred shortcut override, click Apply Scheme and Save changes. Now you can try out the command which was broken before and confirm it works well.

Now you can safely go back to the keyboard layout of your choice and the commands will be at your service.

I have noticed a very unusual oddity which occurs when handling the KeyDown event. When the user hits the ‘Enter’ key, the event is actually fired twice (at least this is the case for
TextBox and
PasswordBox controls on which I have noticed this behavior).

Consider the following code snippet:

C#

1

2

3

4

5

6

7

privatevoidTextBox_KeyDown(objectsender,KeyRoutedEventArgse)

{

if(e.Key==VirtualKey.Enter)

{

Frame.Navigate(typeof(SomeOtherPage));

}

}

What will actually happen when the user actually presses the ‘Enter’ key in the
TextBox ?

As you would expect, the event is fired first time and frame navigates to
SomeOtherPage . But right after the execution of the handler finishes, it is called once again with the exact same arguments! The code will get executed again and the frame will once again navigate – which is (probably) not what you actually needed!

This behavior is really connected only with the ‘Enter’ key and it does not seem to be present for other keyboard keys. Luckily the workaround is simple:

C#

1

2

3

4

5

6

7

8

privatevoidTextBox_KeyDown(objectsender,KeyRoutedEventArgse)

{

if(e.Key==VirtualKey.Enter)

{

Frame.Navigate(typeof(SomeOtherPage));

e.Handled=true;

}

}

By setting
KeyRoutedEventArgs ‘ Handled Property to true we are essentially stopping subsequent bubbling of the event higher up the tree, but this also prevents the event to fire again on the same control.

I have reported this issue in the Windows Feedback app for Developer Platform. If you want to support its resolution in future versions of UWP, vote for it by clicking here.

Windows Presentation Foundation (WPF) apps have a bit harder life in the touch-enabled world. In WinRT apps, the touch keyboard shows up automatically when a text field gets focus so that the user can type without the need of a classic keyboard (no interrupting of her touch workflow). For classic desktop apps the situation differs – TextBoxes don’t cause the touch keyboard to appear and the user has to open it manually. That is obviously very cumbersome.

Hey! How can I get you to my WPF app?

There are two different workarounds for this problem.

The hack-y way

The first solution is quite a bit of hacking. This requires us to turn off the inking support for our WPF app and actually force the system to behave the right way. You will need some COM import and call native Windows API. This process is extremely well describedhere on Brian Lagunas’ blog and I encourage you to try it out. If it works for you, great!

The disadvantage of this solution, that I discovered, is that it interferes with touch “panning” of ListBox controls. Any try to do touch panning only fires ItemClick events on the hovered items and the user needs to scroll using the small scroll bar and that is more than inconvenient.

The simple, but more manual way

To overcome the issues that come after disabling inking support in your WPF app, we can go with a simpler but less automatic solution. We will extend the TextBox control and change its behavior when it gets touch focus.

When the TextBox receives focus after the user enters it with touch, the GotTouchCapture event is called. In this event we can manually start up the process of touch keyboard. The touch keyboard is just a classic desktop application that lives on the path “C:\Program Files\Common Files\Microsoft Shared\Ink\TabTip.exe”.

This solution is very simple and doesn’t require any “hacking” per-se. The only disadvantage is that you as the developer have to ensure, that you use this modified version of TextBox control every time you need to get the right touch-based behavior.

Killing the process

A logical extension to this is to kill the touch keyboard process when it is no longer needed – the input loses focus. The Process.Start( string ) method returns an instance of Process class which provides a Kill() method that will terminate the process when called.

First we need to store the process instance in a private field of the TextBox:

Update – Windows 10 way

In Windows 10, this becomes much less of a problem thanks to the new Tablet mode and settings.

Tablet mode

The newest version of Windows brings a new mode called Tablet mode, which can be turned on via the Action center or in Settings app, and which is optimized for touch first usage. While some see the way it works as a downgrade opposed to Windows 8.1, it presents much more inuitive integration of both new Windows Store apps and classic desktop applications. Each app defaults to full-screen while preserving the multitasking option of two apps side-by-side. Another nice consequence of turning the Tablet mode on is that the touch keyboard is automatically triggered every time any text field gets focus, no matter the type of application. This undoes the need to launch the touch keyboard manually and lets the operating system take the wheel and ensure everything is handled corretly. The only disadvantage as opposed to the modern applications is the fact, that keyboard doesn’t shift nor resize the app window and overlays it (even in case it is pinned to the bottom of the screen). This means, that some content may become invisible (for example tooltips or context menus).

Outside of Tablet mode

But what about the case when you, for some reason don’t want the Tablet mode on but still want to enjoy the automatic handling of text input by the operating system? A inconspicuous setting can make just this happen!

Open the Settings app, go to Devices category and select Typing – here scroll down and you will see a setting that is by default turned off (for some reason, I can’t really understand why) – to show the touch keyboard in case of input while no keyboard is attached. This is the perfect solution for most cases and makes using all apps with touch a very pleasant and consistent experience.

Updated – .NET Framework 4.6.2

In August 2016 Microsoft announced a new update of .NET Framework 4.6.2. In addition to a very useful addition of Per-Monitor DPI for WPF, this update also addressed the problem with touch keyboard.

WPF apps targeting the new version of the framework support automatic invocation and dismissal of the touch keyboard, matching the behavior of UWP apps on Windows 10. That means you don’t have to make any additional changes to your new apps to support the touch keyboard.

With platform dependent native libraries like SQLite we often need to get hold of the right DLL files for the given architecture and copy them to project’s output folder. But how to do it in an easy way? Pre-build event commands give us the answer.

First, you will want to create a folder for the library you want to copy and create subfolders for each architecture you need. In each of those folders just place all the DLLs and supporting files you need to copy.

Now right-click your Visual Studio project’s node in Solution Explorer, select Properties and then Build Events tab in the left pane. You will be presented with two empty boxes. In these boxes you can enter any commands that you want to execute before the project is built or after it is built, respectively.

Now, click the Edit Pre-build … button you are ready to enter your desired command. We can use the simple command line tool xcopy to copy the files from our library folder to the output directory:

1

xcopy$(ProjectDir)..\libs\sqlite\$(PlatformName)\*$(TargetDir)/E/Y

To explain what is going on here. The Xcopy tool has two main parameters – copy source and copy target. My sqlite folder is placed in a libs folder that is one level up from my project’s main directory (which is denoted by the “$(ProjectDir)” string) – hence I first navigate to parent folder by “..\” sequence and then to “libs\sqlite\” here I need to enter the correct subfolder for the current project architecture. We can get the “x64”, “x86”, or other current platform name using “$(PlatformName)” macro. Now finally in this folder I use an asterisk (“*”) to instruct xcopy to copy all files in the folder. The target directory for the build is specified by the “$(TargetDir)” macro and I also give two additional options “/E” (to include subfolders in the copying process) and “/Y” (to always overwrite existing files in the target directory).

Now along with each build action, our command will run and the files we need will be copied to the project’s target directory as we wanted. Simple enough, but saves a lot of manual labor.

The latest Technical preview builds of Windows 10 (build 10547 onwards) received a very interesting treatment for taskbar app icons of several built-in apps like Store, Outlook Mail, Outlook Calendar or Photos app. If you look closely, you can see that not only are the app icons without any coloful square outline (as default for WinRT apps), but they also have several areas filled by the system’s accent color.

I was wondering how this can be achieved. The transparent color is used to make the “transparent” portions of the icon, but the colored fill? I thought that it must be some kind of “default” color that will be replaced by accent color. And as it turned out, I was right!

If you look at the app assets of the Photos app, you can see a surprisingly large number of different icons for “AppList” or Square 44×44 logo. The normal icons for this kind of icon with appropriate scaling are there, but we can also are the ones with “.targetsize-{size}” suffix. These are offered for entry only for four different sizes – 256, 48, 24 and 16 in Visual Studio. But you can apparently offer the system much more resolutions for even more granular scaling – 100, 96, 80, 64, 40, 32 or 20.

But this is where things get even more interesting! There are more different suffixes the Photos app uses!

targetsize-{size}_altform-fullcolor – icons used in File Explorer for associated files, this is a full-colored icon

This is a lot of undocumented file suffixes 🙂 . But the one we are interested here is targetsize-{size}_altform-colorize . This image contains transparent portions for areas of the icon, that are … well, transparent, any other colors for areas that are visible and finally full black areas for those parts that should be replaced by the system’s accent color!

Although the official resources and documentation is so far quite lacking, any developer can use these special icon types in their app right now. Just include the surplus images with the correct naming (same as Square 44×44 Logo) in your app’s assets and all will work as expected. This gives quite a big creative opportunities for developers to make their app look even more alive on Windows 10.

Sample project

You can download a sample project with colorized taskbar icon here. The project is basically the default blank Windows 10 application with just one additional image file in the Assets folder – Square44x44Logo.targetsize-64_altform-colorize.png. This one file does all the magic! Once you run the application, indeed – you will find yourself looking at a very nice colorized application icon on your taskbar. And once you change the system theme, the icon will change as well 🙂 .

The guide covers everything from the basics of the platform itself, through XAML controls, adaptive layout and code, down to the nitty-gritty details and advanced techniques like the concept of “App services”.

So jump in and get your first-hand experience with Universal Windows Platform!

This year for the second time around I attended Microsoft Build 2015 developer conference in San Francisco. Among the biggest highlights of the show was the demonstration of Microsoft HoloLens – the revolutionary holographic reality device coming with Windows 10. I was lucky enough to be able to experience it first hand so I would like to share it now with you.

Register, quickly!

In the first day’s keynote speech it was announced, that the some of the attendees will be able to try out the HoloLens experience for themselves by registering through a dedicated website. One thing that was noted was the fact that the registration will be open right after the keynote ends and it is able to accommodate just a small portion of the large number of developers who are present on the event.

So I acted fast! After the keynote ended I quickly browsed the registration web site on my phone (slowed down by the extreme traffic that all available Wi-Fi networks in the area were getting) and was offered with a choice of three different activities – the Holographic Academy, Holographic presentation and HoloLens One on One. Of the three the One on One session offered the exact activities that were demonstrated in the HoloLens video ad, so I naturally thought of it as the best choice. Sadly, when I tried to choose that activity, my phone (in early preview of Windows 10 Mobile) decided, that the Holographic Academy was the better choice and sent this as my choice. And in the end, I was glad, this one was actually the right one for me!

After an hour, just before lunch, I was lucky enough to receive an invitation in my mailbox to attend the Holographic Academy in a nearby five-star hotel. I had just about 30 minutes to get there so I packed my lunch in the bag and run directly there.

The preparation

In the hotel’s reception area all the invited attendees were anxiously waiting for the signal of the HoloLens staff members that directed them to their chosen activities. The Holographic Academy participants were apparently the largest group and the waiting to be let in was appropriately the longest.

When all was ready, we were let in the elevators to a floor that was dedicated to Microsoft for the purposes of this event.

Right in front of the entrance hall in a glass cube was the Microsoft HoloLens itself for display, but no touching or photography allowed!

We were led to a registration area to sign NDA and had to agree with the fact that we were going to be recorded for demonstration purposes and were handed out a locker key to be able to safely store our personal belongings and all electronic devices, which were of course not allowed on the event itself.

Then we had received our badges and got a measurement of the distance between our eyes. This was for our reference later when we had to configure the initial setup of the device for the optimal experience.

Enter the dev area

After all the formalities were finished and everyone was lined up, we were divided into pairs and each pair of attendees was assigned a supervisor, which acted as our personal assistant throughout the afternoon.

With our supervisor we entered the room where the whole event was about to happen. This room was a medium sized conference hall with a stage in the middle and several sections around it. Each section had a conference table surrounded by three to four tables with two computers each. Every each of us was assigned a seat and a dedicated development machine. Surprisingly, there was no HoloLens on sight yet!

The atmosphere of the room was awesome. The anticipation was palpable and it was clear everyone was eager to get their hands on with HoloLens. In the video below you can see for yourself (by the way, you can catch me at the 0:06 mark).

Introduction

After everyone was in the room and the doors were closed, the one of the event’s presenters entered the stage to introduce us. After a short speech about the device itself and the technology behind it, we were finally handed out the HoloLens device that was going to be “ours” for the rest of the event.

Mind you, HoloLens back then was still in its preview phase. The device no longer required a large battery backpack as in the previous demonstrations and looked like a finished product, but the true holographic version of Windows 10 Holographic was not yet present on the device for example.

Our supervisor helped us set up the device using a preliminary web interface that acted as a temporary substitution for the device’s “so far” non-existent OS interface and allowed us to directly install application packages on it. The OS itself was just an environment where the apps run (just as the Windows IoT Preview looks).

Hello, holograms

After we finished the initial setup we could install our first sample application on the device.

After the app installed, we could finally put the device on. The first great surprise – HoloLens is amazingly light. Although it is a full-fledged computer with high processing power and multitude of sensors, it is really easy to wear and when adjusted correctly it doesn’t even lie on the nose and is extremely comfortable.

The sample application allowed us to place a toy car on any surface around us and then using our gaze and hand gestures instruct the car to drive around the environment. The car was intelligent enough to avoid real world obstacles and was even able to perform stunts like jumping from the table to the floor or driving over my own shoe. All this was extremely realistic as if the car itself was truly a physical object aware of its surroundings and the intricacies of three dimensional reality. The feeling that something like this is being created and presented to me through the lens of a small device on my head was profoundly impressive. This is what is called a mind-blowing experience.

Another thing worth noticing was the image’s stability. No matter how I moved around, the toy car was perfectly stable and didn’t move a bit from its “real world” position. This was maybe even more surprising. I have no idea how the team behind HoloLens was able to achieve this level of stability. Day before the Holographic academy I had a chance to try out the Oculus Rift and I have to say that the difference between those two was like night and day.

Sure, you are probably waiting for me to comment on the field of view, that was described as the biggest setback of HoloLens. Yes, the FOV of the device is smaller than was demonstrated in the previous live showcases and in the advertisements and Microsoft acknowledged that this is a drawback that has to be accepted for the initial release of the device targeted for businesses and developers. I suppose it is mainly an issue of battery life and expect that the second release will expand the field of view enough to be usable for immersive gaming for example. However, I do not feel the field of view was small for normal usage. Most of the objects are visible completely without problems, only a close-up view can cause some cropping of the holograms, which I find more than acceptable.

Let’s //build/!

To bring us back to reality, a bell announced that we should take off HoloLens and come back to pay attention to the stage.

The presenter walked us through the agenda of the rest of the event. We were going to build our first holographic application and become the first developers outside Microsoft to try building for HoloLens.

Our main tools were Visual Studio and Unity – both in pre-release internal beta versions. Unity had a special HoloLens SDK installed that contained prepared tooling for building holographic applications with things like spatial mapping, holographic camera and ambient sound.

Throughout the afternoon we went through the following stages of building a simple app called Project Origami.

Stage 1: Display a hologram

The first and basic stage was just displaying the 3D object in space in front of us. We dragged an pre-composed scene of a origami paper creation in the scene in Unity and placed the Holographic camera.

After preparing the scene, we exported the app as a Windows 10 app and then opened the solution in Visual Studio to allow its deployment to HoloLens itself.

Stage 2: Gaze

First interaction to add to our model was gaze. This enabled HoloLens to track our eye movement and highlight the spot we “look” at. This eye tracking was once again very precise.

Stage 3: Air tap

The second phase of the tutorial added hand gesture – so called air tap. The 3D model contained two paper “balls” levitating in the air. Gazing on one of the two balls and using the air tap gesture, the ball suddenly gained gravity influence and fell down on the floor. In this part of the demonstration however it fell right through the floor into infinity.

Stage 4: Voice

Next up we added voice control as an alternative to the hand gesture. Using our voice we could cause the paper balls to fall and also reset the scene. This made the interaction more natural and demonstrated the freedom the user of HoloLens has when choosing the form of input appropriate for the specific situation. Also worth mentioning is the fact that HoloLens does react only to you and is not confused with people around saying the same thing.

Stage 5: Spatial mapping

To make the holograms aware of the surroundings we added spatial mapping. This was just another of the prepared “plug in” elements in HoloLens SDK for Unity. We just added it and it worked – we could place our hologram on any surface around us and then the paper ball no longer fell down through the floor but correctly interacted with the object around including the table or a sofa.

We were even able to see how HoloLens “sees” the world. Spatial mapping creates a virtual “wireframe” of the environment and very precisely captures the shapes of objects around us.

Stage 6: Ambient sound

To make the experience even more realistic, we added ambient sound. Firstly, the hologram itself exuded a calm, relaxing music and also the falling and rolling of the paper balls was accompanied by sound effect to make them feel real. HoloLens has great sound system built in so the user actually hears the sound as coming from a distance in the right direction. Turning your back to the hologram it sounds like it is truly behind you. Coming closer makes the sound louder. It sounds like a small detail but it makes the experience unimaginably more complete.

Stage 7: A bonus!

To make the experience complete, there was a bonus ready for us at the end of the tutorial. We added an object that was not described more closely to us. When we tried the app then, the falling paper ball caused the floor to break on the impact and revealed a fantasy world below the crack, full of living paper cranes flying around.

Overall impression

Microsoft HoloLens is truly a remarkable technology that sounds, looks and feels like future. I was really blown away by its power and potential and I am sure that anyone who will have a chance to try it will experience the same.

Building apps for HoloLens is be possible in the same way as all other Windows 10 Universal apps. Normal apps will normally work on HoloLens, but if you want to go beyond the boundaries two dimensions, which I definitely recommend, you will really appreciate Unity development environment and the easy-to-use tooling that is at your disposal. Even in its preview form the SDK was extremely straightforward and capable.

The first public release of the hardware is not too far away and I am looking forward to see how the device evolves and what creative uses it can have not only for users, but also for enterprise and even healthcare.

The newest iteration of the number one operating system in the world of PCs brings along a myriad of enhancements and improvements which make it a perfect choice for everyone using a previous version of Windows or a sub-par OS like Mac OS X.

Best of all – it is free for all users of Windows 7 and Windows 8 who upgrade within the first year of its availability.

One Windows

The most important feature for me as a developer is the fact that Windows is now one and the same operating system on all devices – phones, tablets, notebooks, desktops, IoT devices, Surface Hub workstations, Microsoft HoloLens, Xbox One – you name it and all apps will work on it! Microsoft achieved something incredible here – an unified API and runtime, that spans every device in your life. And even better – the apps are able to adapt easily to the device they are running on and behave just as you expect them.

No other company (nor Google nor Apple), is able to achieve this, ever. No other technology company has an operating system that can span such a varied range of devices and even less a application runtime that can run everywhere without much hassle. This is a huge advantage for both customers and developers and is sure to bring a huge number of apps to the Windows ecosystem. By the way – do you know that Android and iOS apps will be able to run on Windows 10 without almost any changes? Surprised? No – this is Microsoft. Now there is no reason for developers to resist building or releasing apps for Windows and the OS has now the potential to have the largest app offering of all.

Start is back

I have to confess – I have loved Windows 8. Many people hated the new user interface it brought, but I loved the modern and fresh approach the system chose.

That being said, I love Windows 10 even more, if that is even possible.

The Start menu is now behaving in exactly the way that makes sense for the device and work mode you are in. Want small contextual menu on desktop? Check. Want full-screen immersive experience when working with the device as a tablet? Check.

The new Start menu also blends seamlessly the world of tiles with classic applications and the result is extremely satisfying.

Modern apps done just right

One of the criticisms Windows 8 received extremely often was the fact that it was no longer “Windows” – modern apps ran in full-screen or snapped mode, unable to be easily integrated in the classical desktop workflow.

This changes drastically with Windows 10 – Modern apps are first-class citizens of the desktop and work just as you expect them with full resizing support, ability to open multiple windows and much more.

The great thing is that all “old” Windows 8 apps work as well without the need for rewriting any code. Because the apps were written with adaptivity to snap mode from the start, resizing is very well supported. This is a stark difference to the likes of Apple iOS, which just now introduced a very limited and half-baked multitasking support for the iPad (well at least for the latest model – because they need to make money, right?), that requires a complete rewrite of the user interface for most apps.

Continuum

The current PC market is filled with devices that can be described as “hybrid” and “2 in 1” devices like the Microsoft Surface Pro. These devices offer the traditional looks of a notebook, but can be transformed into a touch-enabled tablet.

Windows 8 was the touch-first operating system. While offering great usability with your fingers, the mouse and keyboard input was a bit less satisfying. Now that changes drastically with Windows 10.

Windows 10 adapts to the way you currently use your PC. As I mentioned – this automatically includes the Start menu, but also includes all your apps. In the tablet mode, that is automatically triggered when you disconnect or flip the keyboard, all apps go full-screen which is the logical way to use a tablet. You can still do multitasking of two apps at the same time, of course. When you need to have a more powerful workstation, just reconnect the keyboard and go into the classic desktop mode. The transition is seamless and logical – just the thing you would expect from an operating systems that understands your needs perfectly.

Cortana

The first and only true personal assistant Cortana is now on your desktop PC. All features of the phone version are present – including her witty answers and remarks, funny quotes, weather checking, reminders, sports and travel tips, finance tracking and much more. On top of that several new features were added – composing a quick mail message on the fly or finding tips on Windows usage are welcome additions to the growing arsenal of Cortana’s abilities.

And we are still just getting started! Now that Cortana will be available on all operating systems including iOS (including iPad – sorry Siri) and Android (with the ability to directly replace Google Now), we can expect a fast paced tempo of new features and additions to her smarts. Cortana learns about the user in a controlled way (all privacy settings can be controlled by the user), so she can be proactive and help directly with the things that matter most.

Microsoft Edge

The new Browser (B uppercase intentionally). Microsoft decided to retire the Internet Explorer to bring a whole new browser for Windows 10 that matches and outperforms all other browsers on the current market. With automatic updates and latest features, Microsoft Edge is the best thing that happened to browsing on Windows ever. Although it is still in its starting phase, it already offers a great and seamless user experience and is amazingly fast and stable.

Snap assist

Windows 7 brought the productivity revolutionary feature of snapping apps to the sides of the screen. This automatically resized the apps to match the half of the screen and made multitasking a breeze. Now Windows 10 improves on this idea with Snap Assist.

This feature goes beyond the original offering by enabling snapping to corners as well as to the sides of the screen and then offering the user a choice of which complementary apps to place on the screen. It may look like a small improvement, but it goes miles in the usability of the snapping feature.

Windows Feedback

This is something the users should be most excited about.

In contrast with Apple’s and Google’s approach of making changes without any regard to the needs and wishes of the users, Microsoft chose a completely new way of building this new iteration of Windows. Windows 10 was built from the start with direct input of its users. Microsoft announced the beta testing of Windows 10 for tech enthusiasts friendly names Windows Insiders.

Through a dedicated app Windows Feedback can now all users send their ideas for changes and improvements directly to Microsoft. All ideas are considered and used to improve the OS, so you should definitely sound off your opinion, vote for good ideas, because it actually counts!

Do

Windows is for doing. Whether you are an professional, designer, creative, business person, gamer – Windows 10 is made for you. I encourage you to upgrade and enjoy the best Windows ever. The best OS ever.

In my recent Windows 8.1 app project I needed to take advantage of ASP.NET Identity to authenticate in my ASP.NET Web API service. Because Identity offers social (external) logins on top of classic login flow, I decided to integrate them as well. Unfortunately the authentication process required the use of cookies, which needed to be forwarded to the registration endpoint to complete the registration process of a new user. Because the process itself is initiated in a WebView control, we need to obtain the resulting cookies. But WebView does not expose any properties to access them. What can we do?