我正在处理一个项目,我必须通过 ILSpy 从反编译代码构建该项目。当我尝试编译 XAML 代码时,出现此错误:
The attribute 'ConnectionId' from the XAML namespace is not defined.
XAML 的 header 部分定义如下:
<UserControl x:Class="..." Name="..." Loaded="..." SizeChanged="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vtbc="clr-namespace:..."
xmlns:p="clr-namespace:..."
xmlns:local="clr-namespace:...">
而XAML背后的类定义如下:
public partial class ... : UserControl
异常由如下行抛出:
<Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}" x:ConnectionId="16" />
据我所知,它的作用是将数字附加到组件,以便稍后可以附加相应的事件处理程序。
任何人都可以提供提示/想法,我可以在哪里查看或我可以做些什么来解决这个问题?
部分类的另一半:
public partial class ... : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
我注意到它缺少 IStyleConnector
(ILSpy 计数器部分有它)。
编辑:忘了提及项目引用的是什么:
- 微软.CSharp
- 演示核心
- 展示框架
- 系统
- 系统核心
- 系统数据
- System.Datat.DataSetExtensions
- 系统.Xaml
- 系统.xml
- 系统.Xml.Linq
- window
最佳答案
属性 ConnectionId 位于 XAML 命名空间中,如引用所述:https://msdn.microsoft.com/de-de/library/system.xaml.xamllanguage.connectionid(v=vs.110).aspx
xaml 文件根目录中的定义:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
指的是两个 wpf-xaml 命名空间(无前缀)和 xaml 语言(有前缀)。
我从未使用过 ConnectionId,但我希望它驻留在 XAML 命名空间中,正如 msdn 所解释的那样。 然而,情况并非如此,这就是为什么您会收到此错误的原因,因为该属性未在 http://schemas.microsoft.com/winfx/2006/xaml 中定义。 .
但是在 http://schemas.microsoft.com/winfx/2006/xaml/presentation
命名空间中。
关于c# - "ConnectionId"中不存在属性 "http://schemas.microsoft.com/winfx/2006/xaml",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28168899/