Enable / Disable Power Button on Start Screen of Windows 8.1 Update

After installing the Windows 8.1. Update on my Windows RT device, I was missing the power button on the start page (for new features in Windows 8.1. Update, see windows.microsoft.com/en-us/windows-8/whats-new).

Looking around in the Web, I learned that the appearance of the power button depends on the device type and size, not on the CPU architecture (x86/x64 or ARM) – see Windows Experience Blog.

Also, I found a hint about how to change the registry to enable / disable the power button myself.

But this post states that I should add a new value to the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ImmersiveShell\Launcher, which means this change has only effect for the current user. Since I wanted to enable the power button for all users of the device, I added the following value to this key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\Launcher

New value: Launcher_ShowPowerButtonOnStartScreen, type DWORD, value 1

Now all users of my Windows RT tablet have the power button on the start page.

Factory File Manager Updated to Ver. 1.2.1.0

The Factory File Manager was updated:

Ver. 1.2.1.0:
AppBar Seperator Style adjusted
#341: Copy path of focused item to clipboard and show the copied path in lower left corner
#348: Active index immediately changed when opening active tab selection (Ctrl+Tab)
#350: Close ButtonAppBar when “Same Path” was pressed
#352: Changed TextTrimming from WordEllipsis to CharacterEllipsis

Download the latest version from the Windows Store.

“Device Not Functioning” Exception on Invalid PrimaryLanguageOverride Value in Windows Store Apps

Oh, what a title for a post. The correct title is “‘A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)’ Exception Occurs When Showing A TextBox and ApplicationLanguages.PrimaryLanguageOverride Is Set To An Invalid Value in Windows Store Apps on Windows 8.1“.

Symptom

Building the Factory Commander, I was using ApplicationLanguages.PrimaryLanguageOverride to set the culture-correct date and number formatting. This is how the implementation in App.OnLaunched looked like:

ApplicationLanguages.PrimaryLanguageOverride 
  = new GeographicRegion().CodeTwoLetter;

Unfortunately, I can’t recall where I found this approach.

The development of Factory Commander was started on Windows 8, where this approach worked well. But after upgrading the development machine to Windows 8.1, the Commander crashed whenever I tried to rename, copy, or move a single item.

I figured out that, whenever the apps wants to show a TextBox, an exception with the description “A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)” was thrown. The exception did not contain any further information. Well, what kind of device is used by a TextBox that is not used by other common controls of a Windows Store app?

A newly created Windows Store app on the same machine, which did contain a TextBox only, did not threw this exception. Was the Commander not compatible with Windows 8.1? I tested it on a machine having Windows 8.1 initially installed, so no upgrade was made: no problem! Did the upgrade corrupted the development machine?

Then I installed the Commander on a Windows RT device that was upgraded to Windows 8.1: no problem! Was it an issue with upgrading the x64 version of Windows 8? That seems to be the fact, because on another x64 machine that was upgraded to Windows 8.1, the same problem occurs. So I installed Windows 8 x64 on a new virtual machine, upgraded it to Windows 8.1: no problem.

The Reason

As you might assume from the description above, it took me some time to figure out what the cause was. The exception thrown was not really helpful – in other words: absolutely misleading – and the fact that the implementation worked fine on Windows 8, but partially did not on Windows 8.1, wasn’t helpful too. At least the “good” old step-by-step comparison approach made it.

Looking at the docs, ApplicationLanguages.PrimaryLanguageOverride expects a BCP-47 language tag. Valid values are for example “en”, “en-US”, “de”, “de-DE”, and so forth. The Commander set the value to GeographicRegion.CodeTwoLetter, which “… returns the two-letter ISO 3166-1 alpha-2 code for this region“.

If you are lucky, the region’s ISO code will match to the (or at least one) BCP-47 language code. In case you have the region set to “United States” (search for “region and language”), you do not have luck. The return value of GeographicRegion.CodeTwoLetter is “US”, which does not seem to be a valid BCP-47 code.

The Solution

I completely removed the setting of ApplicationLanguages.PrimaryLanguageOverride. The docs mention that “the … setting is persisted between sessions“. Means, the app needs to be uninstalled to have the change take effect.

To format the date and number values according to the user’s regional settings, I am using the CultureInfo of the user’s first configured language now. I was not able to figure out how to get the date and time formatting settings from the system.

// Get all installed languages
IReadOnlyList<string> languages 
  = Windows.System.UserProfile.GlobalizationPreferences.Languages;

// In case we have at least one, set the culture info from it.
// The result will be used later on as parameter 
// of String.Format calls.
CultureInfo = languages.Count > 0 
  ? new CultureInfo(languages[0])
    : CultureInfo.DefaultThreadCurrentUICulture;

I think there should be one language defined at minimum, but who knows what might happen.

Advertisement Side Effects

A side effect of the change was that the Microsoft advertising services started to deliver ads. Before the change, I was wondering why the fill rate (quota number of items delivered by number of requests) was exactly zero. I.e. no ad was delivered at all.

After the change, ads were retrieved. This means that the app’s primary language is used to request ads in the matching language. And having an invalid language set, there will be no advertisement.

Expected Behavior

Letting the user of an API set invalid values without giving any feedback is not really helpful from my point of view.

What I expect from ApplicationLanguages.PrimaryLanguageOverride is to throw an ArgumentOutOfRangeException in case I try to set an invalid value. This would have saved me a lot of time.

It throws an ArgumentException telling the value does not fall within the expected range when I try to set it to a value like “abcd”. But as long as the format of the value matches to the BCP-47 language tag structure, like “ab” or “ab-cd”, no exception is thrown by the setter.

Try It Yourself

Are you curious and want to try it yourself? This is how I was able to reproduce the behavior:

  • Use Windows 8.1
  • Create a Blank Windows Store App, name it as you like (e.g. PrimaryLanguageOverrideTest)
  • Add ApplicationLanguages.PrimaryLanguageOverride = "US"; as the first line of App.OnLaunched
  • Insert <TextBox> into the Grid of MainPage.xaml
  • Start the app in debug mode (press F5)

This will cause the app to crash with the exception described above.

To make the positive test, follow these steps:

  • Uninstall the app (search for it, right-click, choose uninstall)
  • Change ApplicationLanguages.PrimaryLanguageOverride = "US"; to ApplicationLanguages.PrimaryLanguageOverride = "en-US";
  • Start the app in debug mode (press F5)

The app should start now without any problems.

Links

ApplicationLanguages.PrimaryLanguageOverride

BCP-47 language tag

WinRT apps and Regional settings. The correct way to format dates and numbers based on the user’s regional settings?

Factory Commander Updated to Ver. 1.1.0.6

The Factory Commander was updated:

Ver. 1.1.0.6: Fixed item #324 – app crashes when clicking the rename button and then a different item while renaming an item

Ver. 1.1.0.5: Fixed item #322 – app might crash when renaming / copying / moving single item on machines with US region settings; uninstall and re-install might be required for this fix to take effect

Download the latest version from the Windows Store.

Factory Commander Available in Windows Store

Instance Factory’s file commander for Windows 8.1, Factory Commander, is now available in the Windows Store.

Factory Commander is a side by side file management app. Multiple tabs can be created to manage different file locations within the same window. Of course, copy, move, delete, permanent delete, and rename are supported. Folders can be created too. Strong keyboard support is integrated to be highly productive.

The Factory Commander monitors changes of folder content in the background and automatically updates the view.

The features are:

  • Side by side file management (dual pane)
  • Mutiple tabs
  • Background monitoring of folder content changes
  • Copy, move, rename, delete, permanent delete of files and folders
  • Folder creation
  • Strong keyboard support for higher productivity
  • Keyboard, mouse, and touch support
  • Launch files

You can find the Factory Commander here.

Factory Commander Screenshot