Archive for 08:13 PM

Unbelievable!

08:13 PM

Wow! Automatic “func eval” in Visual Studio is cool. You can even do more cool things with DebuggerDisplay (e.g. “rating = great”). If a getter has to do too much work for a debugging session to get his job done you can suppress evaluation by adding a DebuggerBrowsable attribute.

But the nice small Debug Windows “Auto” and “Locals” ignore these attributes. So your debugger will continue to do unnecessary work – an amazing feature. This is especially bad since there is a timeout within the debugger’s evaluator which will kill the debugger to the point of unusability when hit.

And yes – this is by Design:

Entity Framework Designer v1…

12:06 PM

Usually I like Entity Framework. And as I have to write the EDMX files by hand (for several reasons) I didn’t had any problems with mapping my Database and Objects.

But for another project I would like to use the designer. And I would like to use Complex Types. This is a situation where I dont like Entity Framework (or better: the Designer).

Error: ComplexType elements are not supported in the Entity Designer.

Yep – this is a known issue:

So I’ll try not to use Complex Types (with some bad tricks this sould be possible) or I will continue writing EDMX Files by hand…

1:1 Relations and Entity Framework

09:02 AM

Yesterday I tried to declare a 1:1 Relation in Entity Framework. As I have to write the EDMX File by hand (for various reasons) I’ve tried a straight forward way and ran into some problems. But first let me show you the sample Model:

(more…)

WPF ResourceDictionary Syntax

11:52 AM

The current top-hit on WPF ResourceDictionary on Google has a minor error in the usage of WPF’s ResourceDictionary class. Hopefully I can save someone the ten minutes of hate I had while searching for the cause of the strange error the Studio threw at me.

Wrong:


<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="TextStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    <!-- other styles can appear in the resource dictionary too -->
    <Style TargetType="{x:Type Button}"
           x:Key="ButtonStyle">
        <Setter Property="Background"
                Value="#feca00" />
    </Style>
</Application.Resources>

Right:


<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="TextStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <!-- other styles can appear in the resource dictionary too -->
        <Style TargetType="{x:Type Button}"
               x:Key="ButtonStyle">
            <Setter Property="Background"
                    Value="#feca00" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

Note the difference in where the additional <Style>s go.

Doing GUI architecture the Right Way

09:03 PM

WPF binding is great, but directly binding the View to the Model has its limitations. As soon as the Model’s and the View’s structure diverge (which happens quite fast, I was surprised myself) the direct binding approach falls apart. The first example where I hit this was a tree of items which should be displayed and selected in a (decorated) list. Data binding just doesn’t cut it. The solution lies in creating a so called ViewModel.

(more…)

The Ins and Outs of IDataErrorInfo and WPF Binding

02:54 PM

While implementing the business rules to check object validity, I used IDataErrorInfo and Binding.ValidatesOnDataErrors=true to get the validation information to the user.

In some cases I noticed that the WPF Binding didn’t realize that the errors on an object changed. Quickly it became clear that WPF is only checking the IDataErrorInfo when setting or retrieving a value. Which doesn’t happen for a specific property, if a different property, that has influence on the validity of the former property, changes. In retrospect quite obvious.

The solution was to implement INotifyPropertyChanged and trigger Changed events for all affected properties.

I’ve coded a little demo application to show the problem and showcase the solution:

(more…)