Can Of Code

Category Archives: WPF

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 Windows Phone, WPF | Tagged , , , | 1 Comment

C# Quick LINQ example

Recently I’ve been working with LINQ so I thought i’d do a quick post to share the two basic LINQ approaches.

First up is an example of a query that returns a collection of objects. In this case they are RouteItem objects.

 

// The LINQ Query
var routesInDB = from RouteItem route in DB.routeItems select route;

// Populate a ObservableCollection with the query results.
routeItems = new ObservableCollection<RouteItem>(routesInDB);

 

The second example is for when you want to get one item from a query similar to “SELECT TOP 1” or  “SELECT … Limit 1” in SQL.

 

 // The LINQ Query
IQueryable<setting> cityQuery = from c in DB.setting where c.ID == 1 select c;

// populate the setting object with the query result.
setting sett = cityQuery.FirstOrDefault();

 

The example above shows the returning of a single setting object instead of a collection.

The final example shows how to get the number of results. This may be useful if you wanted to see if an item was already present in the collection.

 

// The LINQ Query
var query = from c in routeItems where c.routeName == "home" select c;

// get the size of the returned result set.
int size = new ObservableCollection<RouteItem>(query).Count;

 

This example shows a query to count how many RouteItems have the name “home”. We place the result into an int variable.

 

Posted in c#, WPF | Tagged , , , | Leave a comment

MCTS 70-511 Passed and Advice

A few weeks ago i was pleased to have passed the 70-511 exam! I took the test at Devrill PLC in Poole which a great test centre except perhaps the creaky mice.

The reason i write this blog post is not to just brag about passing but to give some advice to all those who are revising for the test.

The book

If you havent brought the training kit book for this exam, then you really should! The book is really usefull for introducing you to the basic concepts your need to know. I deffently recommend that you do the suggested practises as these get you working with WPF and its the kind of practical experience that the exam is looking for.

The book also includes on the disc a mock test application that allows you to take mock exams to see how your progressing. BE AWARE the questions in the practise tests are rather basic so dont solely rely on the tests as a way of checking your progress.

MSDN

Although the training kit is useful, its not perfect. i found a few areas that the exam might cover that were not even mentioned in the book. This is where MSDN comes in! When you finsh a mock test, you are given the awnsers and with those answers are links to the MSDN site. CLICK THESE! they go into the level of depth that your need for the exam. The way i managed these links was to create a live folder in firefox. then i would put al the links in the folder and slowly work my way through reading them, once i read one i would remove it.

Link: MSDN Website

Measure Up tests

Although you get some mock test software with the training kit, the questions are rather basic and do miss a few areas that may be covered by the exam. I purchased the Measure Up tests software and im rather glad i did. These tests are a lot more detailed with a lot more detailed explinations and better quality links to more information.

Link: Measure Up 70-511 test software

The test

I shall confess, i failed my first attempt of the test. I believe this happened because i didnt proceed to check through the questions a secoud time. When i retook the exam i proceeded to run through all the questions agian. While doing this i noticed how some questions i had answerd were incorrect so i proceeded to change them. My secound point is TAKE YOUR TIME. you really get plenty of time so there is no need to rush.

 

Well i wish all those fellow test takers all the luck!

Posted in Software, WPF | Tagged , , | Leave a comment