【发布时间】:2010-05-08 16:19:14
【问题描述】:
我有一个非常简单的 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 user-controls namespaces