WPF - Writing an IMultiValueConverter (update)
What I didn't realize in the previous blog entry regarding the subject was the fact that binding to a DependencyProperty and performing a string.Format blindly could lead to weird results, e.g.:
Could convert to "DependencyProperty.UnsetValue, DependencyProperty.UnsetValue" The solution is pretty simple:
Happy WPFing!
<TextBlock>
<TextBlock.Text>
<MultiBinding
Converter="{StaticResource StringFormatterConverter}"
ConverterParameter="{}{0}, {1}">
<Binding Path="Customer.Lastname" />
<Binding Path="Customer.Firstname" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Could convert to "DependencyProperty.UnsetValue, DependencyProperty.UnsetValue" The solution is pretty simple:
bool argumentsAreNullOrEmpty = true;
// Check whether all values are null or unset.
foreach (object value in values)
{
if (value != null && value != DependencyProperty.UnsetValue)
{
argumentsAreNullOrEmpty = false;
break;
}
}
// If we have all empty or null arguments, we do nothing.
if (argumentsAreNullOrEmpty)
{
return Binding.DoNothing;
}
Happy WPFing!
7 Comments:
Alternatively, if your object values are intended to be bools, just write
if (value is bool)
since bool is nonnullable, and whenever that dependency property becomes set it should pass through.
By Eric Rodewald, at 12:05 AM
power balance wholesale offers you a competitve price, it saves you much money and time.
This one is also nice, Phiten Necklace.
Emporio Armani
omega-watch
By Unknown, at 10:12 AM
This is the most comprehensive article.
Omkarsoft Website Development Company in Bangalore
Android Application Development Companies in Bangalore
By Unknown, at 12:13 PM
Thank you for your information.
list of marine engineering colleges in india
By Cmc Marine, at 1:42 PM
Very useful blog .
Best International Schools In Coimbatore
By CMCINS, at 2:07 PM
Wonderful content as always, this is very informative and interesting
French Classes Online | Online French Classes
By French language classes in Chennai, at 3:00 AM
Thanks for sharing such a nice Blog.
Permanent Cure for HIV in India | HIV Cure in India
By Unknown, at 8:22 AM
Post a Comment
<< Home