Can Of Code

Increasing the touch area of a Rectangle in XAML

I have been recently working on a Windows Phone project that required a small item to be dragged across the screen.

It was soon discovered that while it worked nicely on the emulator using the precise mouse it wasn’t so easy to use when using my chubby fingers on a REAL device.

The element i was working with was a Rectangle, so after some playing i discovered that creating a large “invisible” stroke around the rectangle would fit the task.

To achieve this i created the rectangle as shown:

 <Rectangle Fill="#FFF4F4F5" Height="270" Width="270"  Stroke="#00FF0000"   StrokeThickness="120" />

 

This XAML creates an invisible hit area of 120 each side of the rectangle using the stroke property therefore creating a rectangle of 30 x 30. The stroke is invisible by using a color with 0% alpha.

 

 

Posted in Uncategorised |

Windows 8 – Adding a Share Contract to your App in C#

I’ve finally started playing around with Windows 8 after spending ages getting it to work in VirtualBox. I struggled to find any sample code / tutorials on adding a share contract in C# so here is my guide.

 

First things first we need to add a import statement:

Using Windows.ApplicationModel.DataTransfer;

 

Next up we need to fetch a DataTransferManager and then associate a method with the DataRequested event. I placed this code in the constructor of the MainPage.xaml.cs.

DataTransferManager manager = DataTransferManager.GetForCurrentView();
manager.DataRequested += new TypedEventHandler(share_DataRequested);

 

Now we need to create the share_DataRequested Method that’s called when a share request is made.

private void share_DataRequested(object sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Sharing something";
    request.Data.Properties.Describtion = "Sharing something with someone";
    request.Data.setText("I'm sharing!");

}

 

The method above is where you tell Windows what data your app wants to share. The example above shows the sharing of a simple string saying “I’m sharing”. The picture below shows how the message will apear once the user select a Share compatible App to share with. On the Enterprise Edition you can only share using Mail by default so you may need to download some other Apps to test the sharing.

 

Your App now makes use of a share contract! If you want to manually launch the Share Contract UI for the user you can use the following code:

DataTransferManager.ShowShareUI();

 

Which will bring up the below UI.

 

Posted in Uncategorised |

Windows Phone Emulator Locations Map Issue

The last few days I have been getting a blank screen when trying to create mock locations in the Windows Phone emulator. After searching I found I wasn’t the only one with various forum threads dedicated to the issue.

Windows Phone emulator showing a blank screen instead of the map.

 

If anyone else is suffering with this problem, a temp fix has been posted by Microsoft which worked for me.

To work around the problem by adding a Browser Emulation mode entry for XDETools.exe in the registry.
caution: The side-effects of this work-around are unknown.  (… I have only done ad-hoc tests to verify it works.)

On 64 bit Windows use:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
“XDETools.exe”=dword:00002328

on 32 bit Windows use:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
“XDETools.exe”=dword:00002328

You can either enter the values manually using the registry editor (regedit.exe) or save the content to a text file with the extension “.reg” and import the file into your registry.  ex: by double clicking on the file in the file explorer or choosing File -> Import… from the menu inside regedit.exe.

And of course, the standard cautions regarding use or the registry editor apply:
Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the “Restoring the Registry” Help topic in Regedit.exe.

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. UseRegistry Editor at your own risk. For information about how to edit the registry, view the “Changing Keys and Values” Help topic in Registry Editor (Regedit.exe) or the “Add and Delete Information in the Registry”.

Posted in Uncategorised |