XAML语法错误是阻​​挡设计师,但编译罚款 [英] XAML syntax error is blocking designer but compiling fine

查看:421
本文介绍了XAML语法错误是阻​​挡设计师,但编译罚款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到一个相当奇怪的事情发生,我有一个的DataGrid 在WPF同时,车桥零部件页面已经定义了以下声明:

I've run into a rather bizarre thing happening, I have a DataGrid defined in a WPF XMAL page that has the following declared:

<DataGrid.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF3399FF" />
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White" />
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#FF3399FF"/>
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="White" />
</DataGrid.Resources>

从技术上讲这两个停用 systemColors中类型与.NET 4.5,但是当它的设置,我可以编译程序目标.NET 4中,而这些非活动画笔工作,但同时,它设置为面向.NET 4加载在Visual Studio中的同时,车桥零部件设计页面引发错误InactiveSelectionHighlightTextBrushKey无法识别或成员不可访问,然后阻止该设计器视图。但它仍然编译和显示为在程序中上述定义

Technically the two Inactive SystemColors types are from .net 4.5, however I can compile the program when it's set to target .net 4, and these Inactive brushes work, but while it's set to target .net 4 loading the XMAL designer page in Visual Studio throws the error The member "InactiveSelectionHighlightTextBrushKey" is not recognized or is not accessible. and then blocks the designer view. But it still compiles and displays as defined above in the program.

这似乎很矛盾,至少可以说,我不能告诉你,这是一个Visual Studio 2012问题,或者如果它允许程序编译,因为安装在我的开发计算机的.NET 4.5,它只是改变了目标框架时,它看到的东西是用它(我很怀疑这虽然)。或者是有可能的不活动类型在.NET 4中,但没有被列为文档的支持,只是造成VS这个问题?

This seems very inconsistent to say the least and I can’t tell if this is a Visual Studio 2012 issue or if it’s allowing the program to compile because my development computer has .net 4.5 installed and it’s just changing the target framework when it sees that something is using it (I highly doubt this though). Or is it possible that the Inactive types are in .net 4 but not listed as supported in the documentation and just causing this issue in VS?

有没有更好的方式来做到这一点。NET 4,让我设置一个DataGrid行的非活动选择颜色?或者是做这个存在升级到.NET 4.5的唯一途径?

Is there a better way to do this in .net 4 to allow me to set the inactive selection color of a DataGrid row? Or is the only way to do this being to upgrade to .net 4.5?

推荐答案

Visual Studio中建立一个程序集,即使它的目标设置为.NET FW 4.0,并使用 InactiveSelectionHighlightBrushKey 在XAML- code。该组件将在系统中正确执行与.NET FW 4.5。但是,如果系统有只是.NET FW 4.0,一个异常将被抛出在系统中创建用户控制 InactiveSelectionHighlightBrushKey

Visual Studio builds an assembly, even if its target set to .NET FW 4.0 and you use InactiveSelectionHighlightBrushKey in XAML-code. This assembly will be correctly performed in a system with .NET FW 4.5. But if the system has only .NET FW 4.0, an exception will be thrown when the system create User control with InactiveSelectionHighlightBrushKey.

所以你不能使用 InactiveSelectionHighlightBrushKey 与靶组件设置为FW 4.0,因为他们不会在只有.NET FW 4.0的系统工作。

So you cannot use the InactiveSelectionHighlightBrushKey in assemblies with target set to FW 4.0, because they will not work in a system with only .NET FW 4.0.

要同时支持固件4.0和FW 4.5,你可以在引发LostFocus / LostKeyboardFocus /的GotFocus 事件处理程序设置所选行的颜色。见例如code http://stackoverflow.com/a/8095932/1815957

To support both FW 4.0 and FW 4.5 you can set a color of the selected row in handlers of LostFocus/LostKeyboardFocus/GotFocus events. See the example code http://stackoverflow.com/a/8095932/1815957

这篇关于XAML语法错误是阻​​挡设计师,但编译罚款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆