Blog posts


    June 14, 2010 | Tags: Actionscript, AS3, Flash
    I thought that the functionality of ROLL_OUT was about the same as MOUSE_OUT. And in many aspects they are. But the big difference is how they handle children:

    MouseEvent.MOUSE_OUT will be raised if a child object recieves MOUSE_OVER.

    MouseEvent.ROLL_OUT will only be raised if the clip that the event is attached to and all it's children looses MOUSE_OVER.

    So, if you use MouseEvent.MOUSE_OUT the event will fire when focusing on a child object. Something that usually isn't what you want. If that's the case, change to MouseEvent.ROLL_OUT and you're all set to go! :)

  • Struct vs Class: By value or reference

    June 07, 2010 | Tags: C#
    public struct Car {
    public int Gears;
    public class Car {
    public int Gears;
    ..looks almost the same. But there's a huge different how they are handled. Structs are always copied as values when assigned to another variable in contrast to classes that copied as a reference to the original object.

    If you run the following code:
    Car car1 = new Car();
    car1.Gears = 4;
    Car car1copy = car1;
    car1copy.Gears = 5;
    ..and Car is a struct, then car1.Gears still would be 4 eventhough the copies Gears was changed. If, instead, Car is a class car1copy would be a reference to car1 thus resulting in car1.Gears also becoming 5.

  • Generating PDF from .Net

    May 26, 2010 | Tags: PDF, ASP.NET, C#
    There are several neat libraries for .Net to create PDF files on the fly. Some rely on you doing all the content by code, others like FO.NET uses XSD to accomplish this.

    Here's a hello world example for FO.NET, first the content:
    <?xml version="1.0" encoding="utf-8"?>
    <fo:root xmlns:fo="">

    <fo:simple-page-master master-name="simple"
    <fo:region-body margin-top="3cm"/>
    <fo:region-before extent="3cm"/>
    <fo:region-after extent="1.5cm"/>

    <fo:page-sequence master-reference="simple">
    <fo:flow flow-name="xsl-region-body">
    <fo:block font-size="18pt" color="black" text-align="center">
    Hello, World!


    And the C# code to generate the PDF from the XSD above:

    using System.IO;
    using Fonet;

    namespace FonetExample {
    class HelloWorld {
    static void Main(string[] args) {
    FonetDriver driver = FonetDriver.Make();
    driver.Render("", "hello.pdf");

    You'll find the open source FO.NET library and documentation how to use it over at Codeplex.

  • Get height of TextBlock in WPF

    May 21, 2010 | Tags: WPF, XAML, CodeProject, C#, Snippet
    Sometimes it's quite nice to get the height of a textblock at the same time it's created. In WPF however there's a couple of events that handle the layout functions when an element is rendered, and before these have been fired, you won't get proper values from the DesiredSize property. The good news is that these can be triggered by the Arrange function. You call the Arrange function with a Rect (rectangle) representing the column width and max height (example below use 1000px, but you might need more for longer texts) of your text.

    TextBlock t = new TextBlock();
    int columnWidth = 310;
    t.FontFamily = new FontFamily("Arial");
    t.FontSize = 20;
    t.Text = "Here goes the text..";
    t.Width = columnWidth;
    t.TextWrapping = TextWrapping.Wrap;
    t.Arrange(new Rect(0,0,columnWidth,1000));
    int textHeight = (int)t.DesiredSize.Height;

  • No Xaml-editor in Visual Studio 2008 problem

    May 07, 2010 | Tags: WPF, XAML, C#, Troubleshooting
    I recently started working on a WPF project in Visual Studio 2008, but didn't get the design mode for the Xaml files to work properly. Trying to turn on the design mode I was faced with the following message:

    There is no editor available for ".xaml". Make sure the application for file type(.xaml) is installed.

    Tried reinstalling service packs and all, but no luch. Until I ran into this thread. The answer given there worked for me too. And it's to close down Visual Studio and then run the following command:

    devenv /resetskippkgs

    Voilá, there was the designer in working order! :)