Monthly Archives: August 2009

evidence nova Silverlight Client is nominated for the Golden Headset Award

I’m proud to announce that our Silverlight project “evidence nova” is nominated for the “Golden Headset Award” in the category Innovations.

image

The Award is for creative and innovative ideas in the categories Innovation, Customer focus and Corporate Social Responsibility.

The award giving ceremony takes places next Thursday in the Grand Casino Bern occasioned by the Swiss Contact Day conference.

For more information please take a look at the following web sites:

http://www.evidence.eu/desktopdefault.aspx/tabid-115/319_read-720/
http://www.cmm-magazine.ch/newsblog/innovation.html

You can find our application request for the award here (in german only, english version follows as soon as possible).

Advertisements
Tagged , ,

The property ‘_UnknownContent’ does not exist on the type

Today I was working on a custom control. I had it all coded up, but when I went to build a XAML fragment which uses the control, it gave me the following two errors:

The property ‘_UnknownContent’ does not exist on the type ‘AnimatedPanel’ in the XML namespace ‘clr-namespace:Nova.Toolkit;assembly=Nova.Toolkit’.

Unfortunately this error message in not a very helpful.  I’m embarrassed to say how long it took me to figure out the problem, so I’m not going to tell you. 
But I will tell you how to solve this if you run into it.

 

My custom control directly inherits from control, because the content should be a list of items and not just one UIElement (not important here…).

public class AnimatedPanel : Control
{
    public ObservableCollection<UIElement> Children { get; private set; }
} 

 

The error only arises when the XAML parser has to parse my custom control (like the following)

<toolkit:AnimatedPanel >
   <Border />
   <Border />
   <Border />
</toolkit:AnimatedPanel >

It’s surprisingly simple to fix the error above: I forgot to declare the content property on the AnimatedPanel as following:

[ContentProperty("Children")]
public class AnimatedPanel : Control
{
    public ObservableCollection<UIElement> Children { get; private set; }
}

This tells the XAML reader to which property to put the child elements.

That’s all.

Tagged

Random values generator for different needs

Currently I’m working on a large Silverlight project where we often need random values for testing purpose during UI development or unit testing.

Recently I’ve implemented a RandomProvider class to generate random values for different needs such as simple values like int, short, long, byte, DateTime, Timespan, Thickness, string as well as complex types such as words, addresses, phone numbers, company names, email adresses, names and so on.

 

image

 

Below is a list with the common method implemented in the RandomProvider class.

    RandomProvider.NextBoolean();
    RandomProvider.NextShort();
    RandomProvider.NextInt();
    RandomProvider.NextLong();
    RandomProvider.NextUShort();
    RandomProvider.NextUInt();
    RandomProvider.NextULong();
    RandomProvider.NextDouble();
    RandomProvider.NextSingle();
    RandomProvider.NextDateTime();
    RandomProvider.NextDate();
    RandomProvider.NextTimeSpan();
    RandomProvider.NextThickness();
    RandomProvider.NextString();

    // returns a random string from the given input parameters
    RandomProvider.NextString("value1", "value2", "value3");

    // generates a "lorum ipsum" word combination
    RandomProvider.NextWords(10);

    // returns a value from the given input parameters
    RandomProvider.NextValue<FontWeight>(FontWeights.Normal, FontWeights.Black, FontWeights.Bold);

    // returns a random enum value from the given enum type 
// If the enum is using the FlagsAttribute (enum values as bit flags),
// it may return a combination of these enum values.

RandomProvider.NextEnum(typeof(RandomProviderTestEnum)); RandomProvider.NextColor(); RandomProvider.NextSystemColor(); RandomProvider.NextSolidBrush(); RandomProvider.NextLinearGradientBrush(); RandomProvider.NextFirstname(); RandomProvider.NextLastname(); RandomProvider.NextSalutation(); RandomProvider.NextEMail(); RandomProvider.NextWebLink(); RandomProvider.NextPhoneNumber(); RandomProvider.NextStreet(); RandomProvider.NextCity(); RandomProvider.NextCompany(); // returns a complex object with firstname, lastname, salutation, eMail, weblink, street, city name, company. // email, phone number and weblink are connected to firstname, lastname and the company. RandomProvider.NextContact();

 

Most of the methods above provides on overloaded signature which takes the minimum and maximum range of the random value. See the example below:

    RandomProvider.NextInt(10, 10000); 
    RandomProvider.NextTimeSpan(TimeSpan.FromMilliseconds(1), TimeSpan.FromMinutes(1)); 
    RandomProvider.NextWords(10, 1000); 

 

Have a lock to this small demo application to get a feeling what the RandomProvider class gives.

You can download the source here

Have fun.

Tagged , ,

Label Control with TextTrimming

Just a while ago, I’ve implemented a label control with a text trim behavior. If the text is longer than the available size of the label the text is truncated like this: “Text is too lo…”

label_texttrimming

Brad Cunningham and Robby Ingebretsen did a similar implementation. Both trimming the text during the measure/arrange call.

The implementation of my trimming functionality is similar to the solutions of Brad or Robby. Additionally, I’ve implemented a calculator class to get the text-width with an integrated cache. This makes the trimming function very fast.

As I saw the great examples of Brad and Robby, I decided to share my code too.

You can find the source code and a live example here:

Source Code / Live Demo

Please note: the source code is an extract of another project and I did not change the namespace.

 

Here are some main decisions for the label control:

  • It derived from Control, because one should not be able to add a child control to it (just like the normal TextBlock control)
  • The template is hardcoded, because nobody should be able to change it.
  • The text trimming functionality is implemented in the MeasureOverride method, because it’s the only place I get the available space from the parent element (including infinity)
  • Each char-width of the text is calculated and cached until the text or some font property changes. This makes the calculation very fast.
  • The class FontDefinitions provides an optimized char-width calculator with an integrated cache.
  • The class FontDefinitions uses a TextBlock to retrieve the text length, because a TextBlock immediately returns the width via the property ActualWidth (without any layout cycle).
  • The memory consumption of the font width cache is very small.
Tagged