The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Longhorn/XAML Property aliasing

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jason Nadal

Posts: 184
Nickname: jnadal
Registered: Dec, 2003

Jason Nadal is an asp.net developer, dabbling in winforms from time to time.
Longhorn/XAML Property aliasing Posted: Feb 16, 2004 9:38 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jason Nadal.
Original Post: Longhorn/XAML Property aliasing
Feed Title: Jason Nadal
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jnadal/Rss.aspx
Feed Description: Restless C#ding
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jason Nadal
Latest Posts From Jason Nadal

Advertisement

Since so many people are talking about using the ContentPresenter to bind data via an alias, I figured it would be a good time to mention the IDataTransformer interface.

All you have to do is create a class to implement IDataTransformer, (and hit [tab] to insert the method stubs, if you're in Whidbey) and you're good to go with base functionality. 

Inside your bound property, just change the declaration a bit:

<SomeTag SomeProperty=“*Bind(Path=SomeDataBinding; Transformer=MyWordLengthTransformer)“ />

And inside your MyWordLengthTransformer : IDataTransformer class, you'll need to change the Transform method to suit your needs. In this rather primitive sample, you'll see that it transforms a string into a string length

public object Transform(object o, DependencyID di, CultureInfo culture)

{

string originalPropertyValue = (string)o;
return originalPropertyValue.Length;

}

For an added bonus of reuse, you can put it inside your <Window.Resources> or <Canvas.Resources> (etc.) tags as shown below:

<TransformerSource def:Name="MWLTransReference" TypeName="MyWordLengthTransformer"/>

and when you use the declaration in the XAML element, you'll use:

<SomeTag SomeProperty=“*Bind(Path=SomeDataBinding; Transformer={MWLTransReference})“ />


 

Read: Longhorn/XAML Property aliasing

Topic: Googling by Filetype! Previous Topic   Next Topic Topic: Can't we all just get along ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use