Why do I get a DependencyProperty.UnsetValue when converting a value in a MultiBinding?

From MSDN: UnsetValue is a sentinel value that is used for scenarios where the WPF property system is unable to determine a requested DependencyProperty value. UnsetValue is used rather than null reference (Nothing in Visual Basic), because null reference could be a valid property value, as well as a valid (and frequently used) DefaultValue. Which … Read more

The point of ValueConversionAttribute class?

You can potentially use the ValueConversionAttribute to determine what types are involved in the converters, and use that information usefully. Look at Piping Value Converters in WPF as an excellent example for the use of ValueConversionAttribute. The example shows how multiple converter classes can be chained, and ValueConversion can be used to pass type info … Read more

WPF ValueConverter – Standard return for unconvertible value

According to MSDN – IValueConverter: The data binding engine does not catch exceptions that are thrown by a user-supplied converter. Any exception that is thrown by the Convert method, or any uncaught exceptions that are thrown by methods that the Convert method calls, are treated as run-time errors. Handle anticipated problems by returning DependencyProperty.UnsetValue. The … Read more

WPF BooleanToVisibilityConverter that converts to Hidden instead of Collapsed when false?

I’ve found the simplest and best solution to be this: [ValueConversion(typeof(bool), typeof(Visibility))] public sealed class BoolToVisibilityConverter : IValueConverter { public Visibility TrueValue { get; set; } public Visibility FalseValue { get; set; } public BoolToVisibilityConverter() { // set defaults TrueValue = Visibility.Visible; FalseValue = Visibility.Collapsed; } public object Convert(object value, Type targetType, object parameter, CultureInfo … Read more

ImageSourceConverter error for Source=null

@AresAvatar is right in suggesting you use a ValueConverter, but that implementation does not help the situation. This does: public class NullImageConverter :IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return DependencyProperty.UnsetValue; return value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { … Read more

Moq + Unit Testing – System.Reflection.TargetParameterCountException: Parameter count mismatch

It’s your Returns clause. You have a 4 parameter method that you’re setting up, but you’re only using a 1 parameter lambda. I ran the following without issue: [TestMethod] public void IValueConverter() { var myStub = new Mock<IValueConverter>(); myStub.Setup(conv => conv.Convert(It.IsAny<object>(), It.IsAny<Type>(), It.IsAny<object>(), It.IsAny<CultureInfo>())). Returns((object one, Type two, object three, CultureInfo four) => (int)one + … Read more

how to pass an integer as ConverterParameter?

Here ya go! <RadioButton Content=”None” xmlns:sys=”clr-namespace:System;assembly=mscorlib”> <RadioButton.IsChecked> <Binding Path=”MyProperty” Converter=”{StaticResource IntToBoolConverter}”> <Binding.ConverterParameter> <sys:Int32>0</sys:Int32> </Binding.ConverterParameter> </Binding> </RadioButton.IsChecked> </RadioButton> The trick is to include the namespace for the basic system types and then to write at least the ConverterParameter binding in element form.

Is there a way to chain multiple value converters in XAML?

I used this method by Gareth Evans in my Silverlight project. Here’s my implementation of it: public class ValueConverterGroup : List<IValueConverter>, IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return this.Aggregate(value, (current, converter) => converter.Convert(current, targetType, parameter, culture)); } public object ConvertBack(object value, Type targetType, object parameter, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)