wpf Xaml 设计器 Visual Studio 2015 中的“无效标记”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30709622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:11:32  来源:igfitidea点击:

'Invalid Markup' in Xaml designer visual studio 2015

wpfxamlvisual-studio-2015

提问by nkanani

I have a project which has several UI culture references like this:

我有一个项目,其中有几个像这样的 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>

In code behind, I have a simple implementation:

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

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

    public int MyData { get; set; }
}

In App_Startup, I have initialized the CurrentUICulture:

在 App_Startup 中,我已经初始化了 CurrentUICulture:

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

When I open any such UI in designer, I receive 'Invalid Markup' with error:

当我在设计器中打开任何此类 UI 时,我收到“无效标记”并显示错误:

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

Any idea why this basic use case will not work in Xaml designer for Visual Studio 2015 RC? I have tried options mentioned in an earlier post, but that does not work (Visual studio 2012 XAML designer invalid markup)

知道为什么这个基本用例在 Visual Studio 2015 RC 的 Xaml 设计器中不起作用吗?我已经尝试过之前的帖子中提到的选项,但这不起作用(Visual Studio 2012 XAML 设计器无效标记

Earlier, when loading the designer, we could see the controls and UI without problems in Visual Studio 2010, 2012 and 2013. We decided to try out Visual Studio 2015 RC, but it appears that this is broken now.

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

采纳答案by avenmore

Further to my comment that changing the target framework to .NET Framework 4.6 solves the problem, I think this is a bug in the VS2015 XAML editor, something to do with changes to the CultureInfo.CurrentUICulture Propertybeing now read-write.

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

As a work-around I changed the app startup to

作为一种解决方法,我将应用程序启动更改为

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

and the XAML to

和 XAML 到

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

and it seems happy with that.

它似乎对此很满意。