in

Dé specialist in .NET trainingen en consultancy

Jo-wen Mei

november 2008 - Posts

  • Dependency Property value precedence

    In WPF, there are a  lot of ways how the value of a dependency property can be affected.

    Here's a list that describes the precedence by which the property system applies the effective value.

     

    At first, it might seem a bit uninteresting because these are just the "inner workings".

    But there is a less obvious implication that you need to be aware of, especially when working with styles/templates.

     

    Check out this code:

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Window.Resources>
            <Style TargetType="Button">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Content" Value="mouseOver" />
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="False">
                        <Setter Property="Content" Value="mouseNotOver" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
        <Grid>
            <Button Height="23" Margin="88,0,115,38" Name="button1" VerticalAlignment="Bottom">Button</Button>
        </Grid>
    </Window>

     

    .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

    One of two triggers is always fired. Either the mouse is over the button or not.

    So at startup, you might expect the Content to have the value "mouseNotOver", right?

    ... nothing happens though....

     

    In the list, check out nr 3: Local Value.

    Setting the Content property in xaml (which happens when you drag a button onto the design surface!) has a higher precedence than the triggers.

     

    So keep in mind: either just type in the xaml manually, or use the designer and remove the property settings that are not required.

    Posted nov 29 2008, 01:01 by Jo-wen with no comments
    Filed under:
  • (JSON) Serialization with EF

    I have two cascading dropdownlists in my application.

    The first one is to select the TagGroups (parent), and the second one shows the matching Tags (child)...

    this is a common scenario where it's useful to apply Ajax to improve the user experience.

    Stephen Walther has a good blog post about this.

    [ be careful when you try his example and copy the code. The javascript variable newnewoption should be newoption ]

     

    The Tags and Groups are defined in my database, and I'm using Entity Framework.

    Filling the first dropdownlist with the TagGroups is easy, as opposed to filling the second one.

    Depending from the selected group, I retrieve the appropriate childs.

    The retrieving part is easy, because EF automatically loads the navigational properties which makes querying a breeze.

    Unfortunately, because of this behavior, you get into trouble trying to (json-)serialize the Tags.

    I received an error while filling the dropdownlist:  "A circular reference was detected while serializing an object of type Tag"

     

    I solved this by returning new Tag instances that don't have any references.

     

    Rick Strahl goes into this stuff a more in-depth, and suggest some other solutions.

  • Many-to-many template for Dynamic Data

    I'm currently working on a project that involves Dynamic Data (DD) and the Entity Framework (EF).

    My model has a many-to-many relationship, which EF handles pretty well. The junction table doesn't show up in the conceptual model.

    Unfortunately, the current version of DD is not able to cope with these scenario's. Luckily, DD guru David Ebbo has created a template for this.

     

    I'll share some details of how I got this working in my project.

    • Copy the templates (I had to manually copy the code into newly addes template files. Simply changing the namespace wasn't sufficient; but that's probably an issue on my machine)
    • Add the routes for ListDetails to global asax. (I had to add the DD prefix, and had to place this entry before the existing DD routes) ....

    routes.Add(new DynamicDataRoute("DD/{table}/ListDetails.aspx")
    {
        Action = PageAction.List,
        ViewName = "ListDetails",
        Model = model
    });

    • Add the AutoFieldGenerator class (in the project where your model is located)
    • Modify the implementation of ListDetails

     

    ps: the column order in your table is relevant! My guess is that the template shows the first non-PK column.

  • I have a confession to make.... I'm a junkie

    a keyboard junkie that is!

     

    I like to keep my hands on the keyboard as much as possible. Grabbing that silly blob next to your keyboard take's precious time...

    That's why I love to work with tools like Coderush from DevExpress. (they have an Express version)

     

    Here are some less known, but very cool shortcuts in Visual Studio:

    F12 : Go to definition

    Ctrl+Shift+7, Ctrl+Shift+8 : Go to definition stack

    SHIFT + F12 : Find all references

    CTRL + ALT + L : Go to solution explorer

    CTRL + \ + E : Go to error list

    CTRL + ALT + down : Go to open file   <- winner of the day!

     

    These are Coderush features:

    Tab : Tab to next reference

    Alt+Left, Alt+Right : Camel-case navigation (in combination with SHIFT for selection)

    Ctrl+W, Ctrl+Shift+W : Expand/shrink selection

     

    there are many many more, but I don't want to flood you with them...

    hope you've learned at least 1 new shortcut!

  • WPF Roadmap

    If you don't like details, just look at the highlights:

     

    image

     

    And if you do, here's a list of the improvements of the netfx 3.5.

    And they released a toolkit that includes: Datagrid, Calendar and DatePicker

    There's a futures kit as well. This contains:

    • Client Profile Configuration Designer - A designer to help you make custom branded installation experiences using the Client Profile
    • Shader Effects BuildTask and Templates - BuildTask and VS Templates that ease the building of GPU-shader based effects for use in WPF
    • Shader Effect BuildTask Source - source code for the Shader Effect BuildTask
    • WPF Splash Screen Item Templates for Visual Studio 2008 Sp1 - VS Item Templates that make it very easy to add SplashScreen to WPF applications in Visual Studio 2008 Sp1
    • WPF SplashScreen Template Setup Sources - Source code for the Deployment project and templates

    And there's a new Ribbon preview

     

    Improvements in netfx 4.0:

    • Offloading more work to the GPU
      • Mainstream GPU hardware continues to improve, more will be done on GPU
    • Better Rendering Quality
      • 4.0: Integration of Direct Write for text clarity
      • 4.0: Layout Pixel-level Snapping
    • More seamless interop with other Technologies
    • Scalability: More Visuals
    • Increased Graphical Richness
      • Enabling PS 3.0 on supported hardware
      • Vertex Shaders
      • Multiple Shaders
      • Shaders in WPF 3D
    • 3D improvements

     

    Future controls:

    • Chart Controls
    • Masked Edit, Smart Edit, Spinner
    • Auto Completion and PickList
    • Property Grid
    • DeepZoom

     

    Of course, there are a lot of improvements in VS 2010 and the xaml parser as well. If you interested in those check out the pdc session!

    Posted nov 04 2008, 12:42 by Jo-wen with no comments
    Filed under:
  • Silverlight and WPF

    With the introduction of Silverlight (SL), Microsoft promised us a we could leverage our existing skills to create RIA's (rich internet application).

    This means SL should be a subset of WPF, which is a big deal!

    So I was scared when I watched Ian Ellison-Taylor's session about sharing skills between both of them. He told us there are differences (no matter how subtle they are) Was Microsoft breaking its promise? ....   fortunately not (yet).

    After the session, I spoke with Laurent Bugnion (author of Silverlight 2 Unleashed), and he could ease me. He collaborates with the product team and told me they're striving to have SL as a subset of WPF, but just didn't make it in this release. 

     

    Only in SL:

    • Specific media features
    • Timeline markers, VideoBrush, and multi-bitrate support
    • Multiscale image
    • Full HTML DOM integration

     

    VS Project Files:

    • Can’t use Silverlight DLL in a .NET FX project or vice versa
    • Source compatible, not binary compatible
    • A VS project file (.csproj/.vbproj) compiles either Silverlight or .NET FX but not both

     

    Control Templates:

    • VSM Control templates for SL controls don’t work in .NET FX 3.5
    • Trigger templates for WPF controls don’t work in SL

     

    Other differences:

    • Silverlight font loading from .xap only
    • OpenFileDialog differences
    • SL supports non-windows keys
    • SL has fewer Markup Extensions {x:Type}, {x:Null}, {StaticResource}, and {Binding}
    • Attributes instead of XML Text values (generally)

     

    Other subtle differences:

    • Double to float in graphics happens earlier in SL
    • SL use 4x4 anti-aliasing, WPF uses 8x8
    • SL uses a simplified line-breaking algorithm
    • SL generally has clipping off, WPF has it on
    • Default fonts and themes are different
    • SL has a simpler Property engine
    • SL has a web-focused (async) input system
    • SL doesn’t update IsMouseOver while animating
    • Various API signature differences
    • Bug differences
    Posted nov 04 2008, 12:11 by Jo-wen with no comments
    Filed under: ,