PDA

View Full Version : Initial support for WPF


Bruno Baia
12-04-2006, 05:33 AM
Hi,

You'll find the code and an example under the sandbox repository.
(get nightly build or use CVS).
Code : sandbox\Spring.Net.1.2.2005.Orcas.sln
Example : sandbox\examples\Spring\Spring.Wpf.Example\Spring. Wpf.Example.2005.Orcas.sln


The Spring.Wpf project is made of XAML markup extensions, a converter for binding and a XSD schema.

The schema is used to provide intellisense but also used by XAML to resolve an element to a type :
(Copy it to the VS2005 XML shemas directory : <Microsoft Visual Studio 8 Directory>\Xml\Schemas\)

xmlns:s="http://www.springframework.net/wpf"


The first markup extension allows you to reference Spring objects from XAML :

<ObjectDataProvider x:Key="Movies" ObjectInstance="{s:Object TheMovieLister}" MethodName="GetAllMovies"/>

<CollectionViewSource x:Key="GroupedMovies" Source="{StaticResource Movies}"/>



The second markup extension adds Spring Expressions support from XAML :
(see documentation (http://www.springframework.net/doc-latest/reference/html/expressions.html) related to Expression evaluation.)

<CollectionViewSource x:Key="GroupedMovies" Source="{s:Expression '@(TheMovieLister).GetAllMovies()'}"/>


If you have problems with Spring expressions and the XML parser, you can split like this (full intellisense here) :

<CollectionViewSource x:Key="GroupedMovies">
<CollectionViewSource.Source >
<s:Expression>
<s:Expression.Value >
<![CDATA[@(TheMovieLister).GetAllMovies()]]>
</ s:Expression.Value>
</s:Expression>
</CollectionViewSource.Source >
</CollectionViewSource>


And finally, an IValueConverter implementation using Spring Expressions that will allow expression evaluation within binding definition, something really useful in XAML :

<DataTrigger Binding="{Binding Converter={StaticResource ExpressionConverter}, ConverterParameter='Year > 2000'}" Value="True">

...

<GridViewColumn DisplayMemberBinding="{Binding Title, Converter={StaticResource ExpressionConverter}, ConverterParameter='ToUpper()'}" Header="Title"/>


That's all for now ! The basics.

The next step is to perform dependency injection into WPF controls...
Ideas are welcome...


Bruno

Bruno Baia
04-27-2007, 12:32 AM
Hi,

I added support for DI on dependency objects, it means you can inject any WPF controls.
The job is done by an attached property.

Exemple with an UserControl :
XAML

<l:MoviesUserControl Grid.Row="1" s:Configurer.TemplateName="DefaultMoviesUserControl" />

Spring

<object id="DefaultMoviesUserControl" abstract="true">
<property name="MovieLister" ref="TheMovieLister"/>
</object>



But you can also inject existing WPF controls :
XAML

<TextBlock Grid.Row="0" s:Configurer.TemplateName="TitleTextBlock" />

Spring

<object id="TitleTextBlock" abstract="true">
<property name="Text" value="All movies :"/>
</object>



- Bruno