Castle Windsor Dynamic Property in XML config
Posted
by haxelit
on Stack Overflow
See other posts from Stack Overflow
or by haxelit
Published on 2010-04-06T22:33:03Z
Indexed on
2010/04/07
1:43 UTC
Read the original article
Hit count: 397
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
© Stack Overflow or respective owner