in

Dé specialist in .NET trainingen en consultancy

Jo-wen Mei

  • Invoking an ICommand

     

    I wanted to reuse the logic of a Command defined in another usercontrol.

    The simple solution would be to create a separate, public method which I then could call from outside the control (and call this method in the Execute eventhandler).

    A more clean way is to directly invoke the Command!

    The ICommand interface supports the Execute(object parameter) method.

    I expose my commands as static properties, so I can have this code:

    SearchCommands.FilterProduct.Execute(null, SearchControl);

     

    I don’t have to reference the commandBinding collection of the search control, which is very clean!

    You can/must specify the input-element with the implementation you want to invoke.....

     

    more info

    Posted dec 30 2009, 07:40 by Jo-wen with no comments
    Filed under:
  • WPF & xaml guidelines

     

    Wpf and xaml has been out for a while now, so the community already knows the do’s and don’ts of programming in xaml.

    Thankfully, there are always some nice people who share this stuff with us.

    This is a good resource and starting point. It also includes links to the channel 9 videos that give you some background info on the rationale of these guidelines.

     

    Some other guidelines/info:

    Designing with WPF

    XAML Guidelines for Creating a Composite UI

    Posted dec 30 2009, 07:10 by Jo-wen with no comments
    Filed under: ,
  • Grid Size Sharing WPF

     

    The other day, I had to show different datatemplates depending on a specific property value. (The datatemplateSelector is your friend!)

    I used different foreground colors to visualize the states; however, the layout design was the same for each datatemplate.

     

    I was using a Grid, and wanted to share the columnWidth’s and RowHeight’s.

    My first solution was specifying a double constant in xaml. Unfortunately, this doesn’t work out of the box. You would need to have a DoubleToGridLengthConverter.

    Then, after some searching I found this Grid Size Sharing sample!

    Basically, you have to define the attached Grid.IsSharedSizeScope on the container element to set the scope of the shared sizes.

    Then when you set the SharedSizeGroup on a row/column definition (together with the width/height of course), other definitions with the same name will automagically adjust as well.

     

    nice!

    Posted dec 16 2009, 10:32 by Jo-wen with no comments
    Filed under: ,
  • Check some (runtime) characteristics of a dependency property

     

    It's pretty easy to inherit from an existing control in WPF.

    For instance, this great programmer I know has written an extended combobox. It has extra functionality, like:

    * Automatically select the value if only one item is available in the items source;

    * Disable the control when no items are in the items source;

    So, there's logic in the inherited class that manages the IsEnabled property.

    Flexibility must remain, so consumers of this control should still be able to set the IsEnabled property, and overrule the default logic.

    Here's a way to programmatically check if the property has been set:

    if (DependencyPropertyHelper.GetValueSource(this, ComboBox.IsEnabledProperty).BaseValueSource == BaseValueSource.Default)

    {

          IsEnabled = !(IsDisabledWhenItemsSourceIsEmpty && (_customItemsSource.Count == 0));

    }

    More info

    Posted dec 11 2009, 05:52 by Jo-wen with no comments
    Filed under:
  • When not implementing the ConvertBack method…

    I really like WPF converters. I often don’t need the ConvertBack method though.

    Most programmers deal with this by leaving the throw new NotImplementedException() , or they return null.

     

    I also see this method being marked with the [Obsolete()]  attribute. I think this totally gives you the wrong impression that it should not be used anymore.

    The attribute is used to inform programmers , not the databinding system.

    And of course, the method is still valid and might get a different implementation later on.

     

    Check out the DependencyProperty.UnsetValue.

    Posted dec 10 2009, 09:33 by Jo-wen with no comments
    Filed under: ,
  • WPF vs Silverlight

    Last week, I was giving a Silverlight training in the beautiful Bergen (Norway).

    I have WPF experience, but I was still struggling with some demo’s because of its differences with Silverlight.

    Silverlight is supposed to be a subset of WPF but that’s not the case (yet). Silverlight even has functionalities that are not in WPF (yet), like the Visual State Manager.

    There’s a nice whitepaper that describes these differences.

    Posted dec 06 2009, 09:38 by Jo-wen with no comments
    Filed under: ,
  • How to debug WPF bindings

    The databinding expert in the field, Bea Stollnitz, has a great post about different options to debug your wpf binding.

    In summary, the options are:

    • The output window
    • Trace sources
    • Trace level (new in 3.5)
    • Converter

    you’ve got to check them out, it will save you a lot of time!

    Posted nov 19 2009, 08:04 by Jo-wen with no comments
    Filed under:
  • Pin a debugger watch

    The fact that Visual Studio has been designed in WPF exposes a ton of possibilities.

    Here’s a cool feature : pinning a debugger watch

     

    Note: these "pinned-windows” even remain after restarting your application!

  • Arithmetic operations in xaml

    Many times, you want to bind a numeric value to another property AND perform some calculation over it.

    For instance, you would like to bind the width of your control to be half the size of its parent control.

    Take a look at this converter

     

    It enables a xaml syntax like this:

    {Binding ElementName=control, Path=ActualWidth, Converter={StaticResource arithConverter}, ConverterParameter=*0.5}

     

    Posted nov 11 2009, 08:53 by Jo-wen with no comments
    Filed under: ,
  • IObservable/IObserver are the non-blocking equivalents of IEnumerable/IEnumerator

     

    I’m experimenting with the new BCL updates in VS2010. One of these is the addition of the IObservable/IObserver interfaces.

    I’m still into grasping the whole thing, but reading this blog gets me excited about this stuff!

    I think this could lead to a new paradigm in the world of asynchronous programming.

  • Code Contracts in VS2010 Beta 2

    Code Contracts helps to reduce bugs by helping you not write them in the first place, or at least catch them sooner.

    They allow the developer to specify pre- and postconditions and more.

    To use this stuff in Visual Studio 2008 you had to download and install a separate tool.

    I’m experimenting with this stuff the first time in Visual Studio 2010, and NetFx 4 contains the System.Diagnostics.Contracts.Contract class, so I assumed everything was in the box…….  [insert quote with assumption and f*ckup here]

    The only thing that ships in the SDK is the contract class - this makes it possible to author contracts and compile code containing contracts without an extra download. But the contracts have no effect in this scenario. So the tools need to be downloaded from DEVLABS to acquire all the functionality!!!

    The team decided to stay out of the Visual Studio train, so they can update it more frequently. They’re trying to have a monthly release cycle.

    forum (with a link to the latest download)

     

    note: after installing the tool, you should get an extra tab in the project-properties page which contains some cool settings. I had to restart Visual Studio before it popped up!

  • Add Reference Dialog finally improved!!

    I really dig Visual Studio, and its dev team always does an outstanding job in adding new (complex) features…

    That’s why it’s so frustrating they didn’t improve the “Add Reference dialog”.

    But I’m not aware of any dialog/feature that has been more complained about, so they could not ignore it anymore….

    they fixed it!!

  • VS2010 Beta2 released

    The beta2 versions of the following products are now downloadable from microsoft:

    Vs2010 Ultimate

    Vs2010 Professional

    Vs2010 Team Foundation Server

    Vs2010 Premium

    Vs2010 DSL SDK

    Vs2010 Team Explorer

    .NetFX 4

     

    ps: this is not the complete list

     

    happy testing!

  • How to delete a Windows Service

     

    short version:

    you can use a command prompt and delete a service using following command: sc delete <SERVICE name>

    (check in the properties for the correct name)

     

    longer version (tnx Shahed!)

    more info on sc

    Posted okt 16 2009, 04:08 by Jo-wen with no comments
    Filed under:
  • Can’t connect to TFS after installing Visual Studio 2008 SP1

    I installed the VS2008 SP1 on our server, and couldn’t connect to the TFS anymore.

    As I was in the process of installing more software updates, I didn’t immediately realize which update caused these problems.

    So I googled on the error message: “TF30059: Fatal error while initializing web service

    and luckily others had the same issue and posted the solution: Install TFS 2008 SP  *sigh*

More Posts Next page »