Tuesday, December 15, 2009

C# Compact Framework: Numeric TextBox

I was recently in need of a numeric textbox for a small compact framework application I’m writing at home. The best I could find on the web was this MSDN article, but unfortunately it wasn’t as bullet proof as I’d like it to be, so I used the code as a base, and wrote my own.

Features:

  • Allows numeric only entry
  • DecimalPlaces property
    • Specify how many decimal places the number should have. 0 decimal places = integer numbers (no decimal separator allowed)
    • Defaults to 2 decimal places
  • AllowNegatives property
    • Specifies whether to allow negative number values or not
    • When the number is negative, the font changes color from black to red
    • defaults to not allow negative number entries

Sample application with code:

The code isn’t exactly pretty, but it works, and that’s all I was after.

Feel free to take it for a spin, and let me know if you can break it, so I can fix any loopholes.

Saturday, December 12, 2009

Daily Links 12/12/2009

She Sells PowerShell on The Sea Shore

Plug into MEF in 10 minutes or less

Building extensible Silverlight applications with MEF

Play sounds in Silverlight using MediaElement

Working with the WebCam in Silverlight 4

Bing Maps Silverlight Control SDK

One bug, two developers: Collaborative debugging is now a reality in Visual Studio 2010

Creating extensions for VS 2010

Crafting Smartphone User Interfaces Using .NET Compact Framework
Some basics of developing UI for smartphone devices

Handango
Develop mobile applications and sell them online

Saturday, November 28, 2009

Daily Links 28/11/2009 Silverlight 4 Special

Silverlight 4 Debuts with Killer Demos at PDC09

Silverlight 4 Beta : A guide to the new features

RIA Services: Jumpstarting RIA Development

Silverlight and Expression Love
Rundown of Silverlight 4 Beta Features and 6 Hands on Labs

Data Binding Changes in Silverlight 4

Enabling Validation in Silverlight 4 with IDataErrorInfo

Silverlight 4 Fluid UI

Walkthrough: The power of the November 2009 Silverlight Toolkit testing tools

Silverlight 4 NotificationWindow and Queuing multiple notifications

Silverlight Validation Workaround

Silverlight 4 dials in skype

A look at the Printing API in Silverlight 4

Silverlight 4's Improved Element Data Binding

Silverlight 4's New Clipboard Support

Bonus:
Silverlight Style: GlassBorderStyle

Wednesday, November 18, 2009

Daily Links 18/11/2009

Prototype of OpenStreetMap Silverlight Control using DeepEarth and Bing Maps SDK

How to Get Your Silverlight Pages Indexed By Search Engines

XAML: Gradients

How to create a Module based Silverlight application (Part 1)

Silverlight’s CollectionViewSource

Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight

Silverlight CAPTCHA examples

Grouping data in a Silverlight DataGrid

Silverlight 3's new Application Extension Services

Model First in Entity Framework 4

Entity Framework 4.0: How to use POCOs

Using Transactions with SqlBulkCopy

Creating Custom Configuration Section C#

The High Cost of Losing a Developer

Monday, November 2, 2009

Daily Links 2/11/2009

Twirling smoke effect in Expression Design

Silverlight out-of-browser and initParams

Caliburn v1 RTW for WPF, Silverlight 2.0 and 3.0!

Simple Kick Start Example using MEF (Preview 8)

Resharper 5.0 Overview

Silverlight Toolkit October 2009 Release

Pivotal Tracker - Lightweight Agile Project Management

SkyDrive Explorer adds 25gb of free cloud storage to Windows Explorer

How to write a book - the short honest truth

Monday, October 26, 2009

GetType From Referenced Assembly In Silverlight

I recently implemented a ValueConverter for our comboboxes in silverlight, whereby the translations for an enum would be shown as a list in the combobox, and when an item is selected, the value bound to the model would be whatever was described on the enumeration as the model value that gets persisted to the database (it’s a legacy database, so I couldn’t save the enumerated value on the model). Anyways, more on how that was done is for another blog post.

The converter gets an enumeration type as a converter parameter, so I needed to construct the type of enum at runtime (so I could get access the the enumerations that were defined, and the ModelValue attributes on each enumeration definition), since the converter should be able to handle any enumeration type that has been defined according to a specific convention. Trouble is, the enumerations were defined in a seperate silverlight assembly that was referenced from the client assembly, so I couldn’t just simply:

   1: Type type = Type.GetType("ClassLibrary1.Class1, ClassLibrary1");

… only if you specify the culture and the version in the above string parameter, will the type get returned, and since those change frequently, it wasn’t a practical solution.

So here’s helper method I wrote to get a type referenced in another assembly:

   1: public static Type GetAssemblyType(string assemblyName, string className)
   2: {
   3:     StreamResourceInfo info = Application.GetResourceStream(new Uri(assemblyName, UriKind.Relative));
   4:     Assembly assembly = new AssemblyPart().Load(info.Stream);
   5:     Type type = assembly.GetType(className);
   6:  
   7:     return type;   
   8: }

Usage:

… if you know the fully qualified class name and which assembly it’s in:

   1: Type type = GetAssemblyType("SilverlightClassLibrary1.dll", "SilverlightClassLibrary1.Class1");

… or if you only know the fully qualified class name, and don’t know which assembly it’s in:

   1: public static Type GetAssemblyType(string className)
   2: {
   3:     Type type = null;
   4:     foreach (AssemblyPart part in Deployment.Current.Parts)
   5:     {
   6:         type = GetAssemblyType(part.Source, className);
   7:         if (type != null)
   8:             break;
   9:     }
  10:     return type;
  11: }

usage:


   1: Type type = GetAssemblyType("SilverlightClassLibrary1.Class1");

Notice that in each case  that the class name that is specified is fully qualified with it’s namespace.


Happy Coding :)

Tuesday, October 20, 2009

Daily Links 20/10/2009

Silverlight 3: Calling a WCF service without a proxy using Binary XML

Silverlight 3's New Client Networking Stack

Clean shutdown in Silverlight and WPF applications
...with some MVVM Light Toolkit usage

Silverlight Toolkit adds DragDrop targets!

Silverlight Streaming to be discontinued
What a pity (it seems the Azure replacement service has costs associated with it) Guess I'm going to have to find another way (or remove) my silverlight advertisement on my blog page now :|

Event aggregator

"Agile is treating the symptoms, not the disease"
Highlighting a need to revert to the simplicity of development we had a decade ago.

LightSpeed 3.0 Beta Release

Microsoft SharedView finally RTM
"Connect with up to 15 people in different locations and get your point across by showing them what's on your screen"
It's free.

Terminals
codeplex project: "secure, multi tab terminal services/remote desktop client"
alternative application - RDTabs

Visual Studio 2010 dates and details

Re-imagining the Desktop with 10/GUI