.net - 无法设置 x :Name ="Root" on UserControl

标签 .net wpf xaml user-controls compiler-errors

我正在尝试将 x:Name 属性设置为 UserControl 的定义,以便稍后将其用于内部绑定(bind):

<UserControl 
    x:Name="root"
    x:Class="ElementManager.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
</UserControl>

它没有编译说:

The type name 'UserControl1' does not exist in the type 'ElementManager.ElementManager'



如果我删除 x:Name 属性,它会编译并且一切正常。这是故意的还是我错过了一些微不足道的事情?

最佳答案

XAML-MSBuild 任务混淆了您的类型 ElementManager具有相同名称的命名空间。给你的类型ElementManager与其周围的命名空间不同的名称。

关于.net - 无法设置 x :Name ="Root" on UserControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14496353/

相关文章:

c# - 尝试在 Xamarin XAML 中的 ActivityIndi​​cator 上设置特定于设备的比例会导致崩溃

c# - 如何动态调用带有可选参数的方法?

wpf - ico文件和png图标文件有什么区别

java - Java 中等效的并行扩展

c# - 另一个窗体关闭后主窗体的更新

wpf - DataGridTextColumn.MaxLength?

c# - DataGrid 文本框 DataTrigger 条件未按预期工作

c# - 提取渐变画笔属性

c# - 如何在特定时间后执行下一个循环?

.net - 通过 .Net 设置 Windows 进程 'Comment'?