IValueConverter Signatures

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
TaterJuice
Posts: 102
Joined: Thu Mar 16, 2017 5:40 am
Contact:

IValueConverter Signatures

Postby TaterJuice » Thu Aug 09, 2018 6:40 am

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.

JS-Support @Userware
Site Admin
Posts: 904
Joined: Tue Apr 08, 2014 3:42 pm

Re: IValueConverter Signatures

Postby JS-Support @Userware » Fri Aug 10, 2018 5:11 am

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


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 3 guests