wpf - 设计时失败 : WPF, 用户控件和命名空间

标签 wpf user-controls namespaces

我有一个非常简单的 WPF 项目,包括一个窗口和用户控件。我正处于学习阶段。当我运行它时它工作正常。但是,我无法在设计时看到表单。问题,我相信与命名空间有关,但我不明白在哪里。这很可能是一个简单的错误

主窗口 XML

<Window 
    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:views="clr-namespace:UserLogin"
    x:Class="UserLogin.MainView"
    x:Name="MainViewWindow"
    mc:Ignorable="d" 
    Title="Login" 
    Height="141" 
    Width="347"
    >

    <Grid>        
        <views:LoginView />
    </Grid>

</Window>

主窗口代码隐藏
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports UserLogin

Namespace UserLogin

    Partial Public Class MainView
        Inherits System.Windows.Window

        Public Sub New()
            InitializeComponent()
        End Sub

    End Class

End Namespace

用户控件 XAML
<UserControl 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" 
             x:Class="UserLogin.LoginView"
             x:Name="LoginViewControl"
             mc:Ignorable="d" d:DesignHeight="96" d:DesignWidth="298">
    <Grid  Height="96" Width="298">
        <Button Command="{Binding OKCommand}" Height="21" Margin="0,0,90,16" Name="btnOK" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="76">OK</Button>
        <Button Command="{Binding CancelCommand}" Height="21" HorizontalAlignment="Right" Margin="0,0,9,16" Name="btnCancel" VerticalAlignment="Bottom" Width="75">Cancel</Button>
        <Label Height="23" HorizontalAlignment="Left" Margin="10,5,0,0" Name="Label1" VerticalAlignment="Top" Width="85">Name:</Label>
        <Label HorizontalAlignment="Left" Margin="10,32,0,0" Name="Label2" Width="85" Height="29" VerticalAlignment="Top">Password:</Label>
        <TextBox Margin="0,31,6,0" Name="txtPassword" Height="22" VerticalAlignment="Top" HorizontalAlignment="Right" Width="182" />
        <ComboBox Height="22" Margin="110,6,6,0" Name="cboNames" VerticalAlignment="Top" />
    </Grid>
</UserControl>

用户控制代码隐藏
Imports Microsoft.VisualBasic
Imports System
Imports UserLogin

Namespace UserLogin
    Partial Public Class LoginView
        Inherits System.Windows.Controls.UserControl

        Public Sub New()
            InitializeComponent()
        End Sub

    End Class
End Namespace

我想我错过了这个命名空间的东西
xmlns:views="clr-namespace:UserLogin"

因为智能感知没有给我在 XAML 设计器中声明的用户控件,而是报告错误“无法加载程序集的元数据......等等”

谢谢你的任何建议

西蒙

最佳答案

我有这个问题并想通了。我在设计器中遇到错误,但在运行程序时它起作用了。在这种情况下,源代码位于网络驱动器上,并且该驱动器没有完全信任权限。我在本地移动了代码,它开始工作了。如果您希望将代码保存在网络驱动器上,您还可以添加完全信任权限。

关于wpf - 设计时失败 : WPF, 用户控件和命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2794756/

相关文章:

sql-server - sp_xml_preparedocument 和 Namespace 的使用。我在 SQL Server 2012 中收到错误 "XML parsing error: Reference to undeclared namespace prefix: ' a'。

c# - 找不到类型或命名空间(但应该是!)

namespaces - TYPO3-升级 4.5 至 6.2 : namespaces

wpf - 关于分辨率与 DPI 的问题?

wpf - IsMouseOver 与 ListViewItem 的 IsSelected 重叠

c# - UserControl 在 Visual Studio 设计器中显示属性,但属性未更改

c# - 为什么我的自定义控件的文本属性不会显示在“属性”窗口中?

wpf - 进入 WPF 的主要好处是什么?

c# - WPF 中的 ScrollViewer 问题

c# - 如果用户控件的数据上下文是 View 模型,如何绑定(bind)到 xaml 代码隐藏中的属性?