Freigeben über


IValueConverter: The Swiss Army Knife of Bindings [PropertyViewer sample is a WPF/Silverlight visualization and debugging aid!]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

PropertyViewer.zip

Comments

  • Anonymous
    May 05, 2008
    Cool - I really appreciate you do everything for both Silverlight and WPF.

  • Anonymous
    May 20, 2008
    Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately

  • Anonymous
    May 20, 2008
    Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately. 

  • Anonymous
    May 20, 2008
    Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately

  • Anonymous
    May 23, 2008
    Mijn verontschuldigingen voor de weinige posts de laatste weken. Mijn werk en leven zijn enorm de druk

  • Anonymous
    June 02, 2008
    Mes excuses pour le peu de publications au cours des dernières semaines – le travail et la vie en générale

  • Anonymous
    June 15, 2008
    Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately

  • Anonymous
    July 04, 2008
    It's a great example. Just as a comment, I like the way Ruby On Rails simplify the binding to objects, letting you get friendly names using the Humanize method. That way using an attribute as [DisplayName("Eats Bugs")] is not need just to split the PropertyName based on the case. Altough the attribute gives you more control. I can see how IValueConverter can be useful in certain escenarios, but most of the time using a FormString would be easier. I dont know if there's something like that in SL or WPF. I did a trick to do something similar using ValueConverters, it work fine, but I think there should be a sexier solution. Here's the XAML. <UserControl.Resources>       <local:StringFormatConverter x:Name="stringFormatter"/>   </UserControl.Resources>   <StackPanel Orientation="Vertical">       <StackPanel.DataContext>           <SilverlightApplication3:Person/>       </StackPanel.DataContext>       <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Mode=OneWay, Path=Name}" TextWrapping="Wrap"/>       <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Mode=OneWay, Path=LastName}" TextWrapping="Wrap"/>       <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text='{Binding Mode=OneWay, Path=DOB, Converter={StaticResource stringFormatter}, ConverterParameter="d"}' TextWrapping="Wrap"/>       <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text='{Binding Mode=OneWay, Path=Age, Converter={StaticResource stringFormatter}, ConverterParameter="c"}' TextWrapping="Wrap"/>       <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text='{Binding Mode=OneWay, Path=AnualIncome, Converter={StaticResource stringFormatter}, ConverterParameter="0.00"}' TextWrapping="Wrap"/>   </StackPanel> Here's de Code public class StringFormatConverter:IValueConverter   {       #region IValueConverter Members       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)       {           string formatString = parameter.ToString();           return String.Format("{0:" + formatString + "}", value);       }       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)       {          throw new NotImplementedException("This Convert supports only OneWay binding");       }       #endregion   }

  • Anonymous
    July 04, 2008
    Miguel, Thanks for the kind words - and brief Ruby On Rails lesson! :) I think your approach to string formatting is totally reasonable and it's something I've done once or twice as well. For what it's worth, this scenario should be much easier in WPF 3.5 SP1 because they've added the Binding.StringFormat property (details here: http://blogs.msdn.com/vinsibal/archive/2008/05/16/new-wpf-sp1-feature-data-formatting.aspx). I'm not thinking that'll make it into Silverlight 2, but it sure would be nice!

  • Anonymous
    July 21, 2008
    (以下内容全部整理自博客堂Scottgu博客中文版)Silverlight技巧,诀窍,教程和链接 【原文地址】SilverlightTips,Tricks,...

  • Anonymous
    September 11, 2008
    When I was writing my video frame grabbing sample , I came up with a potentially useful technique for

  • Anonymous
    February 04, 2009
    When we created Silverlight Charting (background reading here and here ), we tried to make things as

  • Anonymous
    February 23, 2009
    The only comment to the author - stop being a wuss and stop using "null != ..." or "0 == " syntax. Or do you talk in the same way? "if seven dollars costs a beer, then anymore it's not a happy hour". Sheesh...

  • Anonymous
    June 15, 2009
    The comment has been removed