'标记无效'在Xaml设计师视觉工作室2015年

时间:2015-06-08 12:49:14

标签: wpf xaml visual-studio-2015

我有一个项目有几个这样的UI文化参考:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel Orientation="Horizontal" Grid.Column="1">
        <TextBlock Text="{Binding MyData, StringFormat={}{0:C2}, ConverterCulture={x:Static sysglb:CultureInfo.CurrentUICulture}}"  />
    </StackPanel>
</Grid>

在代码背后,我有一个简单的实现:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        MyData = 10;
    }

    public int MyData { get; set; }
}

在App_Startup中,我初始化了CurrentUICulture:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

当我在设计师中打开任何此类用户界面时,我会收到“无效标记”#39;有错误:

The member "CurrentUICulture" is not recognized or is not accessible.

知道为什么这个基本用例在Visual Studio 2015 RC的Xaml设计器中不起作用?我已尝试过前一篇文章中提到的选项,但这不起作用(Visual studio 2012 XAML designer invalid markup

早些时候,在加载设计器时,我们可以在Visual Studio 2010,2012和2013中看到控件和UI没有问题。我们决定试用Visual Studio 2015 RC,但现在看来这已经破了。

1 个答案:

答案 0 :(得分:1)

除了我的评论,将目标框架更改为.NET Framework 4.6解决了这个问题,我认为这是VS2015 XAML编辑器中的一个错误,与现在读写的CultureInfo.CurrentUICulture Property的更改有关

作为解决方案,我将应用启动更改为

CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-GB");

和XAML到

<TextBlock Text="{Binding MyData, StringFormat={}{0:C2}, ConverterCulture={x:Static sysglb:CultureInfo.DefaultThreadCurrentUICulture}}"/>

并且看起来很满意。

相关问题