成员"CurrentCulture"无法识别或无法访问 [英] 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"
包含文本框
<TextBox Text="{Binding Path=Price, Mode=TwoWay, StringFormat='C',
ConverterCulture={x:Static sysglb:CultureInfo.CurrentCulture}}"
MaxLines="1" TextAlignment="Right"/>
根据 Gusdor的回复
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.
Intellisense可以识别并提示sysglb:CultureInfo.CurrentCulture,但是一旦我离开文本框,我就会收到错误消息.
The Intellisense recognises and prompts sysglb:CultureInfo.CurrentCulture but as soon as I move away from the textbox I get the error.
能不能请一些善良的人告诉我为什么会这样以及我要如何解决呢? 还有XAML编辑器如何设法识别sysglb:CultureInfo.CurrentCulture,而标记却没有?
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?
欢呼 杰夫
推荐答案
不记得我从哪里得到的,但是它有用
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;
}
}
}
这篇关于成员"CurrentCulture"无法识别或无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!