Blog

posts tagged with csharp

Windows 8 XAML Tips – Custom Fonts

1 Comments
By Fons Sonnemans, 12-jun-2012

It is time for me to write a series of blog items on writing XAML applications for Windows 8. I plan to write one every two weeks. I hope I can keep up the promise.

READ MORE

MessageBox.Show() in WinRT

6 Comments
By Fons Sonnemans, 12-mrt-2012

I'm currently in the process of converting some of my Windows Phone apps to the Windows 8 Consumer Preview. While doing so I discovered there is no MessageBox.Show() method in WinRT. The alternative is to use the new MessageDialog class. This means I have to rewrite a lot of code which I try to avoid. Therefore I came up with my own MessageBox helper class which mimics the behavior of the WP7 MessageBox. In this post I will demonstrate this, using the following sample application.

Suppose I have the following code in my Windows Phone application:

private void Button1_Click(object sender, RoutedEventArgs e) {
    var result = MessageBox.Show("This is MessageBox", "Title", MessageBoxButton.OKCancel);
    if (result == MessageBoxResult.OK) {
        // do something    
    }
    Button1.Content = result.ToString();
}

In Windows 8 I would have to rewrite it to the following:

READ MORE

My LicenseManager class for the Windows Phone

0 Comments
By Fons Sonnemans, 25-feb-2011

I have developed a few Windows Phone apps which support a Trial mode. In these WP7 apps I use the static IsTrial property of my LicenseManager class to check if the user is using a paid or trial version. This class uses the IsTrial() method of the Microsoft.Phone.Marketplace.LicenseInformation class if you are running in configuration 'Release' mode. If you are developing and running in configuration 'Debug' mode it will return true if the TRIAL conditional compilation symbol is set in your project properties. This makes it easy to test the Trial mode in your code.

READ MORE

SpiralText in Silverlight 4

0 Comments
By Fons Sonnemans, 31-mei-2010

Blend 4.0 includes a new PathListBox control. In Silverlight 4 you can create your own shapes by deriving from the Path class. I have used these two techniques to create this SpiralText sample.

The Spiral class uses ArcSegment objects to create a spiral illusion. It isn't a perfect spiral but it is good enough for me.

The LayoutPath of the PathListBox is set to the Spiral. The ItemsSource is databound to the TextBox.

You can also select the Font, Color, Font Size, Font Spacing and the number of Spirals.

Get Microsoft Silverlight

READ MORE

RightMouseTrigger

0 Comments
By Fons Sonnemans, 09-mei-2010

I have written a Silverlight Minesweepe game in October 2008. I just published an improved version on Silver Arcade which support right mouse click. I implemented it using the following RightMouseTrigger. You can set the SetHandled property to true. This stops the MouseRightButtonDown event from bubbling to it's parent.

I really love Behaviors, Actions and Triggers. I hope you like it too.

public class RightMouseTrigger : EventTriggerBase<Control> {


    protectedoverridestring GetEventName() {

        return"MouseRightButtonDown";

    }


    #region SetHandled Dependency Property


    ///<summary>

    /// Get or Sets the SetHandled dependency property. 

    ///</summary>

    publicbool SetHandled {

        get { return (bool)GetValue(SetHandledProperty); }

        set { SetValue(SetHandledProperty, value); }

    }


    ///<summary>

    /// Identifies the SetHandled dependency property.

    /// This enables animation, styling, binding, etc...

    ///</summary>

    publicstaticreadonlyDependencyProperty SetHandledProperty =

        DependencyProperty.Register("SetHandled",

                                    typeof(bool),

                                    typeof(RightMouseTrigger),

                                    newPropertyMetadata(true));


    #endregion SetHandled Dependency Property


    protectedoverridevoid OnEvent(EventArgs eventArgs) {

        var ea = eventArgs asMouseButtonEventArgs;

        if (ea != null && SetHandled) {

            ea.Handled = true;

        }

        base.OnEvent(eventArgs);

    }


}

READ MORE

CountDown Clock in Silverlight 4

0 Comments
By Fons Sonnemans, 01-apr-2010

A while ago I wrote a FlipClock Silverlight 3 application. I have modified it into a CountDown Clock which you can configure using InitParams. It is written in Silverlight 4 and uses the new Viewbox control to make it scalable. I hope you like it.

You can download the sourcecode from here.

Get Microsoft Silverlight

< object data ="data:application/x-silverlight-2," type ="application/x-silverlight-2"

    width="400"height="200">

    <paramname="source"value="ClientBin/ReflectionIT.Silverlight.CountDown.xap"/>

    <paramname="initParams"value="title=Silverlight 4 RTW,date=2010-04-13 08:00AM-8:00"/>

    <paramname="background"value="white"/>

    <paramname="minRuntimeVersion"value="4.0.50303.0"/>

    <paramname="autoUpgrade"value="true"/>

    <ahref="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.41108.0"style="text-decoration: none">

        <imgsrc="http://go.microsoft.com/fwlink/?LinkId=161376"alt="Get Microsoft Silverlight"

            style="border-style: none"/>

    </a>

</ object >

 

Get Microsoft Silverlight

READ MORE

DevDays 2010 Materiaal

0 Comments
By Fons Sonnemans, 01-apr-2010

Zoals beloofd kan je de Presentatie + Demo's van mijn 'Introduction to WCF RIA Services' sessie van de DevDays downloaden. Je dient eerst wel de Northwind database te installeren op localhost\SQLEXPRESS. Het benodigde installatiescript is ook in de ZIP file opgenomen. 

READ MORE

Mijn WCF RIA Services sessie op DevDays 2010

0 Comments
By Fons Sonnemans, 17-feb-2010

Op 30 en 31 maart a.s. vinden de Microsoft Development Days (DevDays) plaats. DevDays is een evenement dat al 13 jaar dé bron van kennis en inspiratie voor IT ontwikkelaars is. Ook deze keer vinden de DevDays plaats in het World Forum in Den Haag.

Dit jaar zijn de DevDays voor mij extra speciaal omdat ik door Microsoft ben gevraagd om als spreker op de DevDays te verschijnen. Op dinsdag 30 maart mag ik een sessies verzorgen over een onderdeel van Silverlight 4, namelijk WCF RIA Services. Met een goed doordacht Framework, op basis van codegeneratie, wordt hiermee het bouwen van gedistribueerde Silverlight applicaties veel eenvoudiger.

Wilt u ook naar mijn sessie komen luisteren, maar heeft u zich nog niet ingeschreven, ga dan naar www.devdays.nl, want ook u bent uiteraard van harte welkom.

READ MORE

Keyboard selection on Silverlight ListBox and ComboBox

3 Comments
By Fons Sonnemans, 07-feb-2010

Silverlight doesn't support keyboard selection on a ListBox or Combox. I have created a small Behavior which fixes this problem. You can attach the KeyboardSelectionBehavior to a ListBox or ComboBox using Microsoft Expression Blend. You drag it from the Assets and drop it on your ComboBox or ListBox. If you have a custom ItemTemplate you will have to set the SelectionMemberPath property.

Try my behavior below. If you press a key on the ComboBox or ListBoxes it will select the next item starting with the given key.

Get Microsoft Silverlight

The ComboBox in this example is not databound, The behavior uses the Convert.ToString() method to convert the Content of each ListBoxItem/ComboBoxItem to a string. An invariant case insensitive StartWith() comparison is used to find the next item.

READ MORE

Silverlight Behaviors and Commands

0 Comments
By Fons Sonnemans, 21-dec-2009

A few months ago I wrote an blog post about a Silverlight 3.0 LetItSnowBehavior. This Behavior can be used to add a Snow effect to a Canvas. Very usefull if you want to create a christmas card.

This behavior was always showing you falling snow flakes. You couldn't stop and (re)start the gameloop. The best way to implement this is by adding Commands to the behavior. This allows you to select one or more triggers to Start or Stop the gameloop. I have added the Start and Stop properties of the type ICommand to the LetItSnowBehavior class. In the constructor I have initialized these properties with new ActionCommand objects (Microsoft.Expression.Interactions.dll) and delegates to the OnStop() and OnStart() methods. Triggers attached to these commands will execute the these methods.

public class LetItSnowBehavior : Behavior<Canvas> {

 

    privateDispatcherTimer _gameLoop = newDispatcherTimer();

 

    public LetItSnowBehavior() {

        // Create Commands

        this.Start = newActionCommand(this.OnStart);

        this.Stop = newActionCommand(this.OnStop);

 

        // Init timer

        _gameLoop.Interval = newTimeSpan(0, 0, 0, 0, 10);

        _gameLoop.Tick += newEventHandler(gameLoop_Tick);

        _gameLoop.Start();

    }

 

    publicICommand Start { get; privateset; }

 

    publicICommand Stop { get; privateset; }

 

    privatevoid OnStart() {

        _gameLoop.Start();

    }

 

    privatevoid OnStop() {

        _gameLoop.Stop();

    }

 

    ...

You can use Expression Blend to attach triggers to the Commands. Select the LetItSnowBehavior object and open it properties. Click the + button for the Start property and select an EventTrigger. Select the 'buttonStart' as source and the 'Click' as event. You can even add multiple triggers to the command.

Set Triggers on LetItSnowBehavior in Expression Blend 3.0

You can download the code from here.

READ MORE

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.