www.planet-xaml.net
 
  • [WPFXAML]

    FrameworkElements - LIFE

    by Florian Krüsch, October 6, 2007

    Wieder was gelernt! Der Unterschied zwischen UIElement und FrameworkElement ist L.I.F.E. - FrameworkElement ist von UIElement abgeleitet und beherrscht zusätzlich Layout, Input, Focus und Events.

    Gehört in New Features in WPF 3.5.

    Kleiner WPF Tip in dem Zusammenhang: wenn man XAML von Hand schreibt, muss man Properties nicht zwangsläufig für den Typen des desklarierten Objektes setzen, es geht auch auf der Basisklasse, wenn die Dependency Property dort schon definiert ist.

    Also statt

    XAMLProperty auf dem Elementtoggle
    <Rectangle Width="30" Height="30" Fill="Orange">
       
    <Rectangle.ContextMenu>
          
    <ContextMenu>
             
    <MenuItem Header="Hello" />
          
    </ContextMenu>
       
    </Rectangle.ContextMenu>
    </
    Rectangle>

    tuts auch das hier:

    XAMLProperty auf FrameworkElementtoggle
    <Rectangle Width="30" Height="30" Fill="Orange">
       
    <FrameworkElement.ContextMenu>
          
    <ContextMenu>
             
    <MenuItem Header="Hello" />
          
    </ContextMenu>
       
    </FrameworkElement.ContextMenu>
    </
    Rectangle>

    Das ist praktisch, wenn man z.B. ein Kontextmenü mal woanders hinkopieren möchte.

    cheers,
    Florian


    no comments
  •  ^
  • [IronRubyWPF]

    Using IronRuby for WPF ValueConverters

    by Florian Krüsch, October 8, 2007

    Since everyone is talking about IronRuby these days I wanted to try if I could use it with WPF. It's actually pretty easy. There's some info on the IronRuby Wiki on how to execute iron ruby from C#

    What I ended up with is a ValueConverter that essentially takes a ruby block, basically a piece of Ruby code as ConverterParameter and executes its code dynamically to convert a value in a Binding expression.

    The binding expression e.g. to display the letter count of input text then looks like this:
    {Binding Text,ElementName=InputText,Converter={StaticResource RubyValueConverter},ConverterParameter={}{ |value| value.to_s.length.to_s+String.new(" Letters") }}

    This is the block passed to the actual conversion function in Ruby: do |value| value.to_s.length.to_s+String.new(" Letters") end

    If you want to play around with the code, download it here. ["AS IS", no warranties etc ..]

    cheers,
    Florian


    3 comments
  •  ^
  • [ASP.NETTDD]

    System.Web.Mvc

    by Florian Krüsch, October 15, 2007

    Scott Hanselmann hat die gute Nachricht schon vor ein paar Tagen verkündet, Scott Guthrie macht es jetzt offiziell: es wird ein Model-View-Controller Framework für ASP.net geben.

    Warum MVC?

    Ruby on Rails

    Der Shooting Star unter den Web-Frameworks ist elegant und überzeugt durch eine sehr saubere MVC Implementierung und integrierte Unterstützung für Unit Tests. Es ist das Lieblingsspielzeug der Agile Community. Microsoft selbst hat da im Moment nicht viel zu bieten. Klar, es gibt die Web Client Software Factory aber die ist doch um einiges schwergewichtiger und auf spezielle Enterprise-Bedürfnisse ausgerichtet.
    Mit Monorail gibt es an sich schon eine nette Adaption von RoR für ASP.net. Ein MVC Framework von Microsoft mit vollem Support als "First class citizen" in ASP.net ist aber trotzdem eine ganz andere Nummer.

    Nicht jeder mag Webforms

    Der ganze Postback/ViewState Hokuspokus in ASP.net 1/2 kann leider doch nicht zu 100% die Illusion von Statefullness erzeugen. Und wenn man Wert auf sauberes XHTML legt, sind die ID Attribute und ViewState Felder doch ziemlich störend, vor allem in Fällen in denen man sie an sich gar nicht benötigt - ein Datagrid auf das Webform gezogen und nicht aufgepasst, schon "wiegt" die HTML Seite 100k...
    Klar, man kann EnableViewState auf false setzen und die IDs irgendwie rausfiltern, aber wenn man es von Anfang an gar nicht braucht, ist das irgendwie durchs Knie ins Auge.

    Testability

    Controller lassen sich prima über Unit-Tests abklopfen. Die fehlenden Interfaces für HttpContext, HttpRequest usw. werden endlich nachgeliefert und die Abhängigkeit von System.Web an den richtigen Stellen unterbrochen.

    Bei meiner eignen Blog Engine für Planet-xaml (basierend auf Model-View-Presenter) hatte ich mich gründlich über diese Dinge geärgert, die jetzt endlich behoben werden - fehlende Interfaces z.B. für die Klassen HttpRequest/HttpResponse, um Mock Objekte für Unit-Tests zu erzeugen.

    Plugability

    Was mir an dem was ich bisher über System.Web.Mvc gehört habe gefällt ist neben dem Programmiermodell die immer wieder angesprochene offene Architektur - d.h. die Möglichkeit, eigene IoC Container oder ViewEngines einzubinden usw. Ein Monorail Clone von Microsoft wäre bei der ALT.net Crowd auch sicher nicht besonders gut angekommen.

    Da das Framework auf ASP.net basiert wird es sicherlich ohne die Unzulänglichkeiten auskommen, mit denen Rails bei aller Eleganz zu kämpfen hat (wer will schon auf C zurückgreifen, um eine Webanwendungen flott zu machen?).

    cheers
    Florian


    no comments
  •  ^
  • [Silverlight]

    Silverlight Showcase Update

    by Florian Krüsch, October 19, 2007

    Die Silverlight Showcase Site wurde ge-updated und erstrahlt in neuem Look and Feel :

    Die Animationen und Übergänge sind butterweich und irgendwie fühlt es sich ein bischen an wie die Media-Center Oberfläche, was mir persönlich sehr gut gefällt.

    "Germany" ist geographisch noch nicht vertreten, also fange ich jetzt mal schnell an, was nettes in Silverlight zu bauen :)

    cheers,
    Florian


    no comments
  •  ^
  • [WPFSilverlight]

    WPF SP1, WPF 1.5 und Silverlight

    by Florian Krüsch, October 24, 2007

    Seit Silverlight ist es etwas ruhig geworden um WPF. Dabei ist die aktuelle Version 1.0 von Silverlight doch eher mager, ausser man steht auf Javascript und Web-Videos.

    Bei all dem Wirbel, wäre mir fast entgangen, dass das ServicePack 1 für Vista auch ein Update für WPF enthält, das die Integration mit dem DWM verbessert (Desktop Window Manager, das Ding, das auch für den Flip-3D-Wow-Effekt zuständig ist). Damit werden Animationen endlich richtig smooth, Apple User werden staunen.

    Im .NET Framework 3.5 sind ein paar nette Features dazugekommen, vor allem im Bereich interaktives 3D.
    Schade, dass das erst jetzt kommt, diese Features hätten in den OTTO Store sehr gut reingepasst.

    Auch das DataBinding ist verfeinert worden, u.a. wird jetzt IDataErrorInfo unterstützt. Damit kann Validierungslogik ohne Abhängigkeiten von WPF sauber getrennt in Business-Logik wandern. Ein Schritt mehr in Richtung saubere Architektur.

    Ich hoffe, dass Silverlight zumindest einige grundlegende WPF Features dazulernt. Denn erst wenn Silverlight DataBinding, Commands, RoutedEvents und ein paar Controls unterstützt, würde ich von einem echten Subset von WPF/XAML sprechen. Und dann wird die Sache auch richtig interessant.

    cheers,
    Florian


    no comments
  •  ^
  • [WPFArchitecture]

    WPF - DM-V-VM or M-V-P - WTF?

    by Florian Krüsch, October 25, 2007

    In the early days of WPF (they are over now, today is Silverlight), there was an app called Microsoft MAX that combined photo-gallery with an RSS reader and looked pretty neat.

    Dan Crevier, a member of the team at Microsoft, who build MAX, then went and described the underlying design pattern, which he called the DataModel-ViewModel-View pattern.

    Microsoft MAX

    You can read all about it here.

    It took a while until I realized that this is an incarnation of what Martin Fowler describes as PresentationModel.

    What's special about DM-VM-M is that View and ViewModel are glued together using DataBinding quite heavily. DataBinding is a very powerful concept in WPF and this is a nice way to do it.

    Basically what DM-VM-M gives you is something that is very close to the view, but separated and testable: a model of the view. The VM also contains the logic that talks to the data-model and that's why I would not choose to implement it for more complex types of apps.

    Instead, what I favor is a variation of the Supervising Controller Pattern, which Martin Fowler describes here.

    A Supervising Controller type Model-View-Presenter architecture fits very well with the powerful databinding machinerie of WPF and allows very good testability of the behavior of an application.

    Basically what you do it set the DataContext of the Window or the current view (UserControl) to the object model, so you can bind your data against it. You add Commands in XAML and expose the CanExecute and Executed events in the view interface. It makes sense to add a little bit of translation logic there that removes the Routed- aspect and casts the command parameter to type that's actually data-bound.

    e.g.

    C#IViewtoggle
    interface IView 
    {
       event EventHandler<CommandExecutedArgs<Item>> 
                        EditExecuted;
       event EventHandler<CommandCanExecuteArgs<Item>> 
                        CanExecuteEdit;

       void ShowEditDialog();
    }

    C#Controllertoggle
    class SupervisingController
    {
       private IView _view;
       private IDataModel _model;

       
    // ... handle view events
       
    // ... handle data model events

       
    // ... tell view what to display
       
    // ... tell datamodel what to do
    }

    DM-M-VM does have its place, but it's not the only way to design WPF apps. In fact I would use DM-M-VM for simple apps where you want to maximize testing on the view. If there's a bit more logic involved, I'd go for a Supervising controller approach, where the view basically manages itself and the presenter encapsulates the logical behavior.

    cheers,
    Florian


    2 comments
  •  ^
 

Language | Sprache

All[e]  |  english  |  deutsch
Tags
 

Profile

Florian Kruesch

I am working as a freelance software architect, developer and consultant in Düsseldorf, Germany.

My focus is on Microsoft technologies and .NET 3.0, especially WPF, ASP.net and SQL Server.

I've been a lead programmer on the WPF development of the OTTO Vista Store at SinnerSchrader Studios.

My client list includes DHL, LG and Ogilvy Interactive.