Page 1 of 1

IValueConverter Signatures

Posted: Thu Aug 09, 2018 6:40 am
by TaterJuice
In WPF and Xamarin, the IValueConverter interface is implemented with the following signatures:

Code: Select all

#region Assembly PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\PresentationFramework.dll
#endregion
using System.Globalization;
namespace System.Windows.Data
{
    public interface IValueConverter
    {
        object Convert(object value, Type targetType, object parameter, CultureInfo culture);
        object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
    }
}

However, in CSHTML5, the signature uses culture\language as type of string instead of CultureInfo.

Code: Select all

#region Assembly CSharpXamlForHtml5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// C:\Program Files (x86)\MSBuild\CSharpXamlForHtml5\AssembliesToReference\CSharpXamlForHtml5.dll
#endregion
using System;
public interface IValueConverter
{
    object Convert(object value, Type targetType, object parameter, string language);
    object ConvertBack(object value, Type targetType, object parameter, string language);
}


Is there any plan to update your signatures to match the accepted Microsoft signatures? I use CSHTML5 in a shared project, and this forces me to create many, many duplicate converters just for CSHTML5.

Re: IValueConverter Signatures

Posted: Fri Aug 10, 2018 5:11 am
by JS-Support @Userware
Hi,

- WPF uses this old signature and the old "System.Windows.*" namespaces. You can have them in CSHTML5 by creating a project of type "CSHTML5 SIlverlight Migration" (suitable for WPF too in spite of the name).
- WinRT and now UWP (Universal Windows Platform) use the signature with string language, as well as the new namespaces "Windows.UI.Xaml.*". You get those when you create a standard CSHTML5 project. We made this choice because UWP is newest of the Microsoft technologies.

You can solve your issue by:
- either replacing the standard CSHTML5 project with a project of type "CSHTML5 SIlverlight Migration" (suitable for WPF too)
- or using the "#if CSHTML5" compiler directive when declaring your converters, like this:

Code: Select all

public object Convert(object value, Type targetType, object parameter,
#if CSHTML5
    string language)
#else
    CultureInfo culture)
#endif


Feel free to let me know if it is not very clear.

Regards,
JS-Support