Castle Windsor Dynamic Property in XML config
- by haxelit
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