header image
 

Caliburn.Micro–Building an module-based application–Part I–The basement

Part I: The basement
Part II: From basement to second floor

First of all I want to tell what Caliburn.Micro (herein after referred to as CM) actually is.
”A small, yet powerful implementation of Caliburn designed for WPF, Silverlight and WP7. The framework implements a variety of UI patterns for solving real-world problems. Patterns that are enabled include MVC, MVP, Presentation Model (MVVM), and Application Controller.” Caliburn.Micro on CodePlex

When I started using CM I was surprised how easy DataBinding in WPF can be. CM handles the binding with implemented naming conventions, so the view “ModuleAView” is bound to the viewmodel “ModuleAViewModel” just by removing the "”model” part from the viewmodels name. Controls are bound by name too. A Button named “SayHello” (x:Name=”SayHello” in XAML) is bound to the method “SayHello()” in the related viewmodel. Seems to be easy, doesn’t it?

Now, let’s come to the core of this post: the module-based application using CM. To give an idea what is meant with a module-based application, take a look at the following draft:
app_structure

There’s the main application window (ShellView by default, can be renamed) containing a collection of separate modules. Each module contains a collection of different module screens. This examples constraint is, that only one module is active/displayed and only one screen of the active module is displayed. Let’s take a look to some source code…
(NOTE: Because this is a very simple example, I did not structure the project like I normally do.)

Shell (ShellView + ShellViewModel)
ShellView.xaml

<Window x:Class="CaliburnMicroWPF.ShellView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid Background="White">
        <ContentControl x:Name="ActiveItem"/>
    </Grid>
</Window>


ShellViewModel.cs

using System.ComponentModel.Composition;

namespace CaliburnMicroWPF
{
    [Export(typeof(IShell))]
    public class ShellViewModel : IShell
    {

    }
}

That’s the basement of the application. To get the modularity, it needs to create views and viewmodels for every module and every screen as well. The navigation logic has to be implemented either in the shell, the modules or in the screens themself. My favourite approach is an event-based navigation to get a well-separated application. Therefor CM provides its own EventAggregator which is accessible with

IoC.Get<IEventAggregator>()

 
For more information about the EventAggregator look here.

To the end of this part, there’s our basement consisting of the ShellView and the related ShellViewModel as the top-level. You can download the example project here. In the next part, the modules will be added to the project to provide the second-level of the module-based application.

Wenn Erfolge sich die Hand reichen…

Manchmal gibt es Phasen im Leben, wo einfach mal alles nach “dem großen Plan” zu laufen scheint.
Manchmal gibt es Phasen im Leben, wo eine positive Überraschung der vorigen folgt.
Manchmal gibt es Phasen im Leben, wo Erfolge sich die Hand reichen…

Es ist nun ca. 1,5 Wochen her, seit für mich so eine Phase begonnen hat und nun wohl erst einmal wieder ein Pause einlegt.

Am 28.01.2011 bestand ich die 1. Microsoft Zertifizierung meines Lebens
=> MCTS: SQL Server 2008, Business Intelligence Development and Maintenance
MCTS - SQL Server 2008, Business Intelligence Development and Maintenance

Am 01.02.2011 bestand ich dann die nachfolgende Zertifizierung; ebenfalls von Microsoft
=> MCITP: Business Intelligence Developer 2008
MCITP - Business Intelligence Developer 2008

Ich darf mich nun MCITP für MSBI schimpfen
MCITP Logo

Am 04.01.2011 hatte ich das wohl bisher wichtigste Bewerbungsgespräch in meinem Leben. Es ging dabei um die direkte Übernahme nach dem Ende meiner Ausbildung.
=> Auch mit einem unguten Gefühl im Magen bekam ich nur wenige Stunden später die Mitteilung, dass meine Bewerbung erfolgreich war.

Sowas nenne ich eine Aneinanderreihung glücklicher Ereignisse, welche jedoch ohne mein eigenes Zutun wohl nicht zustande gekommen wäre.

Wollen wir hoffen, dass sich diese Erfolgsphase zur schriftlichen Abschlussprüfung und zur Verteidigung meiner Abschlussarbeit wieder aufrappelt und ich noch 2 weitere Erfolge anhängen kann…

In diesem Sinne: Wer macht und tut, soll nicht unbelohnt bleiben…

Lame PHP

I know that PHP has its right to exist, but in the short time I am working with it (about already 30 hours… -.- ) it is still not my favorite. My personal number one is .NET and till this moment I do not believe that PHP would ever change this ;)

I mean, look at .NET… it is structured very well and with a well-chosen IDE/editor you have a great syntax highlighting which is missing to about 90% when you using Eclipse for PHP.  .NET gives you the ability to develop desktop applications (console, WinForms, WPF) as well as web applications (ASP.NET and Silverlight) while PHP is only useful in web development. The biggest minus of PHP in my eyes is the missing of typed variables; it is a “faux pas”. You can feed one variable with a string value an din the next moment you are feeding it with a datetime.

Where is the sense?

If anyone can tell me some things about PHP that would change my opinion so please do that as a comment…

Entity Framework + Silverlight

How-To Access a database in Silverlight using the Entity Framework

Accessing a database in Silverlight using the Entity Framework is a little tricky, as I now since a few days. To prevent you from spending a lot of hours searching for a solution I want to give you a little How-To. In my example I will use Visual Studio 2010 Professional and the “Silverlight Business Application” project template. OK, let’s start…

Open your Visual Studio and create a new Silverlight Business Application. In Visual Studio, it have to look like this:
When you create this project, Visual Studio will automatically create a web project for hosting  your Silverlight application. In this project we will do our first steps regarding to this how-to.

In your {application name}.Web project, create a new folder labeled “EntityFramework” and add a new “ADO.NET Entity Data Model”.  Connect it to an existing database or create your database design in the model designer an create a database with it.

Now let’s come to the Web Service which will deal the data exchange between the database and your application. Again in your .Web project, create a new folder labeled “WebService” and add a new “Silverlight-enabled WCF Service”. You can find it in the Silverlight category of the “Add new item…” dialog. This will create a *.svc file and its code-behind file. In this code-behind you can handle your queries for the database.

After you completed your WebService your Solution Explorer should look like this:

You can go to your Silverlight application and add a new service reference by right-clicking its project name and choosing  ”Add Service Reference…”. In the following dialog choose “Discover” to find you even created WebService and add it. Once your WebService is referenced you can access it by insert the using {application name}.{reference name}.{service name}Client. Remember that all methods of your WebService are asynchronous methods which means that you have to register the {method name}Completed event of your service instance when the methods have a return value != void. You can access the return value of your method in the {method name}OnCompleted by using e.Result which will give you a value of the return type of the method.

A few of you will now say: “Hey that was easy “. I said this too, after I found out all this stuff but the difficulty was to find out ;)

Neue Runde, neues Glück

Nach einer unglaublichen langen Pause von 3 Wochen, startete am 10.10.2010 die neue Saison der Rostocker Straßenliga. Mit der neuen Saison kamen auch neue Verhältnisse. Nachdem in der letzten Saison noch 13 Mannschaften pro Staffel existierten, so haben sich diesmal nur 10 Mannschaften pro Staffel. Auch die Ost-West-Verteilung wurde ein wenig über den Haufen geworfen, da nun weniger Mannschaften aus West-Rostock mit von der Partie sind.

Streetfighters hatten einen robusten Start gegen  Greif Rostock. Nach anfänglichen Schwierigkeiten in der Chancenauswertung und einem Stand von 3:0 zur Halbzeit, trieb uns unser Trainer in der Pause nochmal zu Höchstleistungen an, welche er promt, wenn auch nicht ganz 100%ig, zu sehen bekam. Das Spiel endete mit einem 12:1 für Streetfighters. Zu diesem Match sollte noch gesagt werden, dass es sich bei Greif Rostock um ehemals Südstadt Union II mit einem überarbeiteten Kader handelt.

Alles in allem war der es ein gelungener Start sowohl für Streetfighters als auch für die anderen Favoriten der Staffel B.

Wer sein X liebt, der schiebt

Aus eigener, wenn auch schmerzlicher Erfahrung, kann ich nun sagen:

Wer seinen Roller liebt, der schiebt…

Als ich heute so auf dem Weg zum Fußball war, fuhr ich im Stadthafen auf der B105 durch eine Bodendelle und schwupps, hörte ich meinen Motor nur noch aufheulen… Der erste Gedanke: Keilriemen gerissen. Wäre an sich nicht so schlimm, wenn ich nicht gut ne Stunde Fußweg von zuhause entfernt gewesen wäre… -.- Zu meinem Glück passierte dies auf Höhe einer Tankstelle udn ich dachte mir, dass die bestimmt ne Ratsche mit ner 8er Nuss parat haben. Fehlanzeige… -.- So rief ich also meine Eltern an und bat um Hilfe und das nötige Werkzeug. Weiterhin meldete ich mich vom Fußball ab, da ich das Spiel wohl oder übel vergessen konnte. Während ich nun also auf meinen Vater wartete, kamen mir noch andere Gründe für die fehlende Übersetzung in den Sinn und meine Panik stieg mit jedem Weiteren. Kurbelwelle gebrochen, Riemenscheibe kaputt, Variator kaputt, Kupplungsglocke kaputt… All das wären Schlimme Sachen gewesen, die einen Besuch in der Werkstatt und hohe Kosten mit sich geführt hätten. Als mein Vater dann mit dem so dringend benötigten Werkzeug eintraf und ich den Variodeckel entfernen konnte, machte mein Herz einen kleinen Sprung, da ich sah, dass es dann “doch nur” der Keilriemen war, der den Geist aufgegeben hatte. Nach dem Entfernen der kläglich kleinen Überreste und dem Schließen des Variodeckels machte ich mich auf den Weg nach Hause. Nun da ich zuhause bin, kann ich weiterhin bestätigen:

Wer seinen Roller liebt, der schiebt…

Wer wissen möchte, wie so ein gerissener Keilriemen nun aussieht, hier bitte:

Mirror effect for controls in WPF/XAML

Hi,

today I want to show you a very nice mirroring effect on controls which is defined only in XAML.

Start opening a new WPF application and you’ll see two open tabs (Windows.xaml and Window.xaml.cs).
You should see something like this, depending on your projects name:

  1. <Window x:Class=”WpfApplication1.Window1″
  2. xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
  3. xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
  4. Title=”Window1″ Height=”300″ Width=”300″>
  5. <Grid>
  6. </Grid>
  7. </Window>

Now you have to add the control you want to mirror. In my case I will add a simple Button control. Notice that the control will be played inside of a Border which is placed inside of a StackPanel. Let’s have a look:

  1. <StackPanel HorizontalAlignment=”Center” VerticalAlignment=”Center”>
  2. <Border>
  3. <Button>Hello World!</Button>
  4. </Border>
  5. </StackPanel>

When we want to mirror/reflect something which is defined in XAML the VisualBrush is our best friend. It’s like every common brush but it can paint other visual elements which derives from Visual. To make our reflection visible, we need some placeholder to put the reflection inside. I will take a Border control but it should work with any other container control as well.

When you add the Border you’ll notice that its Height is totally different to our Buttons Height, so let’s define the Buttons Height with 25 and the Borders Height too.

IMPORTANT! To make our VisualBrush drawing our Button, we have to assign the x:Name property of it. When you want to add a VisualBrush into a container you have to use the containers BackgroundProperty. The VisualBrush is binded with its Visual property to the control which it has to draw. When you want to have a reflection effect you have to perform a ScaleTransform on the VisualBrush.

To add some nice looking effect on your reflection, you can define the OpacityMask property on the container which is holding the VisualBrush.

When you just follow my instructions, your code should look like this:

  1. <StackPanel HorizontalAlignment=”Center” VerticalAlignment=”Center”>
  2. <Border>
  3. <Button Height=”25″ Width=”150″ x:Name=”ReflectionButton”>Hello World!</Button>
  4. </Border>
  5. <Border Height=”25″>
  6. <Border.Background>
  7. <VisualBrush Visual=”{Binding ElementName=ReflectionButton}”>
  8. <VisualBrush.Transform>
  9. <ScaleTransform ScaleX=”1″ ScaleY=”-1″ CenterX=”20″ CenterY=”12.5″></ScaleTransform>
  10. </VisualBrush.Transform>
  11. </VisualBrush>
  12. </Border.Background>
  13. <Border.OpacityMask>
  14. <LinearGradientBrush StartPoint=”0,0″ EndPoint=”0,1″>
  15. <GradientStop Offset=”0″ Color=”Black”></GradientStop>
  16. <GradientStop Offset=”0.9″ Color=”Transparent”></GradientStop>
  17. </LinearGradientBrush>
  18. </Border.OpacityMask>
  19. </Border>
  20. </StackPanel>

And the result:

Ende im Gelände

Nun ist auch der lezte Spieltag gelaufen…

Leider ist das Spiel um den dritten Platz 2:2 ausgegangen, wodurch die die Platzierungen des Dritten und Vierten (siehe vorherigen Post) nicht veränderten. Somit stehen nun auch die PlayOff-Begegnungen der ersten Runde fest und lauten wie folgt:

Alster Union - Streetfighters So. 12.09.2010, 14:00
Alster Union II - Südstadt Union So. 12.09.2010, 16:00
SG Aqua Rostock - Abteilung Suff So. 12.09.2010, 15:00
Baltic FC - Next Generation So. 12.09.2010, 15:00

Es bleibt nun also abzuwarten, wer sich hier gegen wen durchsetzen kann und letztendlich der diesjährige Meister der Straßenliga wird.

Mein persönlicher Favorit ist Alster Union, da diese sich auch in den letzten Jahren immer durchsetzen konnten.

Es tut mir so Leid!!!

Ich habe einen schweren Fehler begangen und somit das größte Glück meines Lebens aufs Spiel gesetzt.

Manch einer mag meinen, dass Fehler dazu da sind, etwas aus ihnen zu lernen und meist sind dies kleine Fehler, wie z.B. beim Abschreiben erwischt werden und merken, dass es falsch ist. Doch es gibt auch solche Fehler, die in ihrem Maß an Dummheit nur noch von dem Maß der Auswirkungen übertroffen werden können.

Ich habe einen Fehler begangen. Doch anstatt aus ihm zu lernen und ihn zu beseitigen, versuchte ich ihn zu vertuschen und machte damit einen weiteren Fehler; den wohl größten in meinem Leben…
Ich habe aus Angst, den ersten Fehler zu gestehen, versucht, ihn zu verbergen, doch als dieser nach außen hin sichtbar wurde, wurde mir bewusst, dass das Verbergen des Fehlers der größere Fehler von beiden war.

Es gibt viele Zitate über das Begehen von Fehlern und einige sind einfach so stimmig, dass ich sie hier einfach aufführen muss:

„Alle Fehler, die man hat, sind verzeihlicher als die Mittel, welche man anwendet, um sie zu verbergen.“
(François de La Rochefoucauld (1613-80), frz. Schriftsteller)

“Der schlimmste aller Fehler ist, sich keines solchen bewusst zu sein.”
(Thomas Carlyle)

“Die schlimmsten Fehler werden gemacht in der Absicht, einen begangenen Fehler wieder gutzumachen.”
(unbekannter Autor)

Ich würde alles dafür tun, dass mir dieser Fehler vergeben wird, doch ich weiß, dass es viel, sehr viel verlangt ist, denn mit diesem Fehler habe das Vertrauen, der mir wichtigsten Person missbraucht…
Ich weiß, dass eine einfache Entschuldigung hier nichts bringt, denn eine Entschuldigung bringt das verlorene Vertrauen auch nicht wieder zurück. Auch dauert es sehr lange bzw. ist es unmöglich, dass das verlorene Vertauen jemals wieder in einem solchen Maß vorhanden sein wird.

Wenn du das liest, dann will ich dir hiermit sagen, dass ich alle Entscheidungen, die du als Reaktion auf meine Tat triffst, verstehen werde. Aber ich werde niemals aufhören, dich zu lieben. Auch wenn nun nichts mehr so sein wird, wie vorher, so hoffe ich, dass du mir verzeihen kannst, denn das ist das Einzige worum ich dich bitte und überhaupt bitten darf, nachdem was ich dir angetan habe…

ICH LIEBE DICH!!!

Hello World

Hi there,

today I would like to introduce you into the world of .NET programming with C#. Let’s start with a very simple console application which will print “Hello World!” on your screen just like this:


To create this nice output, you simply have to follow the steps below.

  1. Open Visual Studio (or any other IDE for C#) and create a new console application
  2. Into the body of the Main method, you have to put the following two lines:
    Console.WriteLine(“Hello World!”);
    Console.ReadKey();
  3. Run your application and Voilà, there it is ;)

Let me explain, what these two lines of code are doing. The first line does print the text “Hello World!” into your console window and the second line makes your application stay open until you’re pressing a key. Without this second line your window would not be visible long enough to see your sentence.

To make my declaration visible, look at the picture below:

That’s it^^

Have a nice day with your “Hello World!” program and be  busy ;)

 

WP SlimStat