Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The member "CurrentCulture" is not recognized or is not accessible

I have a Window with the following namespace

xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"

that contains a textbox

<TextBox Text="{Binding Path=Price, Mode=TwoWay, StringFormat='C',
                 ConverterCulture={x:Static sysglb:CultureInfo.CurrentCulture}}"
                MaxLines="1" TextAlignment="Right"/>

as per Gusdor's reply to StringFormat Localization issues in wpf which was working fine but now Visual Studio (2013) is giving me an "Invalid Markup" - The member "CurrentCulture" is not recognized or is not accessible error.

The Intellisense recognises and prompts sysglb:CultureInfo.CurrentCulture but as soon as I move away from the textbox I get the error.

Could some kind soul advise why this is happening and what I do to fix it? Also how the XAML editor manages to recognize sysglb:CultureInfo.CurrentCulture yet the markup doesn't?

Cheers Geoff

like image 229
Geoff Scott Avatar asked Dec 15 '14 04:12

Geoff Scott


1 Answers

Can't remember where I got this from but it works

using System.Globalization;
using System.Windows.Data;

namespace SomeNamespace
{
    /// <summary>
    /// This class is a fudge because
    /// 
    ///         xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
    ///         
    ///         <TextBox Grid.Row="2" Grid.Column="1" 
    ///              Text="{Binding Path=SelectedSupporterCategory.Price, Mode=TwoWay, StringFormat='C',
    ///              ConverterCulture={x:Static sysglb:CultureInfo.CurrentCulture}}" 
    ///              UseLayoutRounding="True" MaxWidth="100" HorizontalAlignment="Left" MinWidth="100" HorizontalContentAlignment="Right"/>
    /// 
    ///     is giving 
    ///             Error 29    "The member "CurrentCulture" is not recognized or is not accessible."
    /// 
    /// Instead we use
    /// 
    ///         <TextBox Grid.Row="2" Grid.Column="1" 
    ///              Text="{CultureAwareBinding Path=SelectedSupporterCategory.Price, Mode=TwoWay, StringFormat='C',}" 
    ///              UseLayoutRounding="True" MaxWidth="100" HorizontalAlignment="Left" MinWidth="100" HorizontalContentAlignment="Right"/>
    /// 
    /// </summary>
    public class CultureAwareBinding : Binding
    {
        public CultureAwareBinding()
        {
            ConverterCulture = CultureInfo.CurrentCulture;
        }
    }
}
like image 65
Geoff Scott Avatar answered Sep 22 '22 07:09

Geoff Scott