Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Intercepting xaml DataTemplate of a given DataType

已查看 16 次
跳至第一个未读帖子

Alessandro Riolo

未读,
2009年4月8日 12:01:202009/4/8
收件人
Dears all,

since a few months I am working on a project where we use integrate
WPF with and IOC, Castle Windsor (through the extension of the
Composite WPF Contrib).

One of our xaml file would look like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/
xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Presentation="clr-namespace:XXX.Modules.MyForm.Presentation"
xmlns:WinForms="clr-namespace:XXX.Modules.Common.WinForms"
xmlns:Converters="clr-namespace:XXX.Modules.Common.Converters"

<converters:booleanenumconverter key="YYYConverter">
[snipped other converters]
<DataTemplate DataType="{x:Type
Presentation:MyFormPresentationModel}">
[snipped template xaml]
</datatemplate>
</resourcedictionary>

I wrote a couple of interceptors (inheriting from IInterceptor and
implementing Intercept), but when I try to use them resolving the
presentation model, the xaml DataTemplate resolves to a string (the
name of the generated proxy, something as
IMyFormPresentationModelProxy1de831fc74a341249b67...), not to the
instanced object (which stepping in in debug I can see it is
registered and then created and then also proxied correctly, as far as
I can understand). This is exactly the same behaviour we get if we try
to use the interface (i.e. setting the DataType to "{x:Type
Presentation:IMyFormPresentationModel}" we get a string as well
instead of the object).

Using the .Net reference source symbols (and/or deblector) I have been
trying to step in on the exact bit of code which is setting that
string instead of the correct proxied object or even the underlying
instanced object, but with no luck so far.

I do think the issue may be with the xaml engine being unable to match
the proxied type with the DataType of the DataTemplate, and I found
out the .Net framework may perform that using the TypeExtension/
MarkupExtension/DataTemplateSelector classes and possibly some
implementation of the IXamlTypeResolver interface. From a quick
search, I found out nowadays people is using those mostly to provide
some support for generics in xaml (see i.e. "How To Get
ParserContext", http://social.msdn.microsoft.com/forums/en-US/wpf/thread/435ee321-f10c-4828-903b-7f3d3317a08d/,
or "Limited generics support in Xaml",
http://blogs.msdn.com/mikehillberg/archive/2006/10/06/LimitedGenericsSupportInXaml.aspx).

From a purely theoretical point of view, I don't like much the idea to
have to modify the xaml files to be able to intercept them, so I am
not absolutely sure I have been missing something.

Before trying to spend some time on that (i.e. writing our own
TypeExtension), I thought it could be better asking around here is
someone with previous experience or also some insight on this kind of
scenario.

Last but not least, although I don't guess this is a Windsor bug (or
at last I cannot yet see why it should be :)), we are using Castle
project assemblies built from the revision 5380 of the 19th October
2008 in the trunk.

--
ale
http://ale.riolo.co.uk

0 个新帖子