Martin Suchan – BloQ Just another WordPress site

11Jun/140

Xbox 360 Controller API for Windows Store apps

In Windows Store apps for Windows 8.1 there are four basic input methods - touch, mouse, stylus and keyboard. In most of scenarios these input methods are all you need, but in case you want to offer more natural experience for controlling games on Windows 8.1, you can also add support for Xbox 360 and Xbox One controllers.

In this dev article I'll show you, how to use in any C#/XAML app or game for Windows 8.1 the Xbox 360 Controller API, how to detect presence of such controller and how to poll for current state of all buttons.

25Mar/140

Using Json Design-time data in Windows Phone 8 apps

In my previous article I've shown a new way, how can we use Json file as a data source for design-time data in new Windows 8.1 apps. Luckily, it's possible to use similar approach in Windows Phone 8 apps as well!

15Mar/141

Using Json Design-time data in Windows Store apps

When designing Windows 8.1 apps it's essential to have design-time data available in some way, so we can actually see how the app will look like.

Iris Class described in this great article, that there are several ways, how to achieve this:

  • Using XAML – Design time data source set in XAML
  • Using a ‘standalone’ data source class – Design time data source set in XAML
  • Conditional data source – Design time data source set in code

But what I missed in this aticle is probably the most interesting way, how to use design-time data in Windows 8 apps - using external Json files. Here's a short guide, how to do it:

8Mar/140

WPdev know-how in my open sourced app Bugemos

Capture1

Just today I've published one of my first Windows Phone application Bugemos as Open Source on GitHub.

The app, that I created and published to Windows Phone Store back in late 2011, is just a simple RSS reader displaying latest comic strips from the web http://www.bugemos.com. The reason I'm publishing it as Open Source is that I think it might give a helpful insight to starting WP developers and to the community as well. Note the published source code is not the exact one, that was used in the currently published app. The app was updated from WP7.5 to WP8 and also instead of original AsyncCTP it now uses current Microsoft.Bcl.Async NuGet package.

So let's see, how is the application designed and what it does.

23Jan/143

New API in Windows Phone 8 GDR3

In this article I describe new developer APIs available in Windows Phone 8 GDR3/Update 3, at the time of writing this article the latest official version of Windows Phone OS.

First of all, GDR3 brings officially no new API, only minor changes in OS behavior, support for 1080p devices, devices with 2GB of RAM, couple of new Uri schemes and that's basically it. But what you might have noticed last week, Pedro Lamas described in his article  Disabling screenshot functionality in a Windows Phone app one undocumented new property

  • PhoneApplicationPage.IsScreenCaptureEnabled

After reading that article I was wondering, if there are another new APIs available in the GDR3 update, that can be accessed by reflection, so I stared my analysis.

11Nov/132

Tip: hiding programatically the “volume bar” controls on Windows Phone 8

windows-phone-volume-bar

Just a simple tip, what I just discovered recently - you probably know that when you play any music file or tune FM radio station on Windows Phone 8, this volume bar controls appear, when you press Volume Up/Down buttons. But even when you stop the music playback, there is no simple way, how to remove this media playback bar.

But since there is already at least one app, that can remove this Volume bar, I was wondering, how to do it in C# as well.

After couple of minutes tinkering with the MediaPlayer class I've discovered the solution, and it's pretty easy:

  • You need to add into your app empty file with .wma extension and set the build action as "Content", for instance "empty.wma" into the app root folder.
  • To stop the media playback and remove the media player just create dummy Song object and try to play it like this:
Song s = Song.FromUri("empty", new Uri("empty.wma", UriKind.Relative));
MediaPlayer.Play(s);

And that's all :)
Note I've tested this only on Windows Phone 8 device with GDR3 update, but I guess it will work on WP7.5 as well.

Filed under: Tips&Tricks, WP8, WPdev 2 Comments
4Nov/132

How to debug most common memory leaks on WP8

When developing Windows Phone application, which is more complex than just 3 screens and couple lines of text, you'll probably face the well-known problems of memory leaks. Even when using modern platform as Windows Phone 8, without pointers, with Garbage Collector, IntelliSense and everything, it is still quite easy to experience memory leaks in your apps.

In this article I'll go through 3 most common problems that are causing leaks when developing Windows Phone apps: Images, abandoned Pages and leaks in native controls. I'll also shown you simple trick, how to find your leaks early in the development and not two weeks before project deadline :)

26Sep/137

Shared localization for Windows Phone 8 and Windows 8 apps using Portable Class Libraries

When developing Windows Phone 8 or Windows 8 app for more wider audience, you need to think about the localization. Unfortunately the localization on each platform uses completely different approach:

On Windows Phone 8:

  • Standard resx files with strings for each language are used.
  • The default language, for instance "en", has localization in file without any suffix, typically just AppResources.resx.
  • Other languages uses files with culture specific suffix, like AppResources.de.resx, AppResources.cs.resx, etc.
  • For supporting non-default languages it's required to check the additional languages in WMAppManifest.xml file and in the project settings as well
  • Localization in XAML is done typically via databinding to viewmodel class, that has instance of AppResources class, typically:
  • <TextBlock Text="{Binding Loc.AppTitle, Source={StaticResource Localization}}"/>
  • in AppResources.resx:   |   AppTitle   |   Hello world!   |
  • For accessing the localized string programatically you can use:
  • string text = AppResources.AppTitle;
  • Globalization and localization for Windows Phone

On Windows 8(.1)

  • Windows 8 uses for localization new file types ending with .resw, but actually they use completely equal structure as WP8 .resx files.
  • Each file must be placed in a separate folder, for instance English localization should be placed in Strings/en/Resources.resw, German localization in Strings/de/Resources.resw
  • There are no automatically generated Designer.cs files for these resw files, but you can create manually ResourceLoader class for returning localized strings.
  • In Windows 8 the localization of Controls in XAML is done differently. Rather than assigning directly values using databinding, you just name each localizable control with x:Uid property and then add entry for localizing such property directly into resw file:
  • <TextBlock x:Uid="TextBlock1" Text="DesignTimeText"/>
  • in AppResources.resw:   |   TextBlock1.Text   |   Hello world!   |
  • For accessing the localized string programatically you can use:
  • ResourceLoader resourceLoader = new ResourceLoader();
    string text = resourceLoader.GetString("TextBlock1.Text");
  • Application resources and localization sample (Windows 8.1)

As you can see, the recommended localization uses completely different approach in Windows Phone 8 and Windows 8. Sharing resx files using links, or even copying them or renaming is just not feasible to maintain. Beside these obvious differences, there are even other caveats:

  • Accessing localized strings in Windows 8 projects programatically is really cumbersome and you can make simply error, because you have no direct compile time check, that "TextBlock1.Text" actually exists in the resw file.
  • You cannot share any localized XAML code between Windows Phone 8 and Windows 8, because of the different localization method

Let's see, how to solve this mess once and for all

6Jun/130

Windows 8 Share Task out-of-sandbox vulnerability

When I was recently developing one Windows 8 app that supports the "Share Contract", I've experienced strange problems when the sharing suddenly stopped working not just in my app, but for all apps launched from my account. I had to log-off and log- in to make it work again. I thought it was just some kind of temporary issue until I discovered that it cause my app. After hour of testing I've pinpointed the actual issue and came to conclusion:

Any Windows 8 app running in sandbox can break the Share Contract for ALL other Windows 8 apps running under the same account, until the user logs off and on again!

Here's the detailed explanation how to do it, it's quite simple, nothing tricky.

16Mar/114

Fixing Lightword Theme in Internet Explorer 9

I have found some time ago, that my blog is not properly displayed in latest Internet Explorer 9 - all headers are gone. I just ignored this issue for some time, until now - final IE9 has been released, it's a sign to do something about it. Well, I googled what the problem might be - when inspecting the structure of a page I noticed, that all headers are written using some strange <cufon> tags.  As I found, Cufon is a very interesting way how to incorporate non-standard fonts on a web pages, but sadly in IE9 it wasn't working as expected.

There are basically two usable solutions - the easy one and the right one. In the easy one just add meta tag to your page saying "render this page in IE8 compatible mode":

<meta http-equiv="X-UA-Compatible" content="IE=8" />

This works, but somehow we all feel it's not the right solution.

The right one is just downloading fixed version of cufon.js library and replacing existing cufon-yui.js file in Lightword Theme folder. Sounds pretty easy:

You can download the updated file from this location. It's also good idea to minify the size of this file using for example this site. Done.

Source

Filed under: Tips&Tricks 4 Comments