views:

132

answers:

1

I'm trying to set the DataContext on ApplicationMainWindow which is a WPF window. When I set it up in the XML like so it leaves the DataContext null:

<!-- View Models -->
  <component
            id="mainwindow.viewmodel"
            type="ProjectTracking.ApplicationMainViewModel, ProjectTracking"
            inspectionBehavior="none" lifestyle="transient">
  </component>

  <!-- UI Components -->
  <component
            id="mainwindow.view"
            type="ProjectTracking.ApplicationMainWindow, ProjectTracking"
            inspectionBehavior="none" lifestyle="transient">
    <parameters>
      <DataContext>${mainwindow.viewmodel}</DataContext>
    </parameters>
  </component>

But if I do it this way via C# it works.

        _Kernel.Register(
            ...
            Component.For<ApplicationMainWindow>()
                .DynamicParameters( (k,d) => {
                    d["DataContext"] = k[typeof(ApplicationMainViewModel)];
                    })
        );

I'm instantiating my window like so:

Window window = _Kernel[typeof(ApplicationMainWindow)] as Window;

When I configure windsor via the xml config it leaves my DataContext NULL, but when I configure it via code it works like a charm.

Do I need to use code to pull this off, or should it work via XML config ?

Thanks, Raul

+1  A: 

You're defining inspectionBehavior="none" which tells Windsor to ignore properties as points to inject optional dependencies. Removing that attribute will restore the default behavior and the datacontext property will be injected.

Mauricio Scheffer
Oops, I guess that's what I get for copy/paste code :)Thanks!
HaxElit