WPF页面xaml中如何引用类库的命名空间

RedErick 2009-04-04 02:22:06
a.xaml文件:
<Page x:Class="MyWpfTest.Page3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyWpfTest"
Title="Page3" Loaded="Page_Loaded">
<Page .Resources>
<model:Ca x:Key="Ca1"/>
</Page .Resources>
<Grid Name="gRoot">
</Grid>
</Page>
a.xaml.cs文件:
using TestModel;

namespace MyWpfTest
{
/// <summary>
/// Interaction logic for Page3.xaml
/// </summary>
public partial class Page3 : Page
{
public Page3()
{
InitializeComponent();
}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
TestModel.Ca c = new TestModel.Ca();
}
}
}
类库文件
b.cs
namespace TestModel
{
public class Ca
{
}
}
问题是想在页面中引用并不在同一个命名空间的类Ca.已经添加了引用,但是只是后台正常,前台不知道怎么办,如果在同一个命名空间,
可以用xmlns:model="clr-namespace:MyWpfTest.Model"
但是如果不在,应该如何处理,各位大侠遇到这个问题该怎么办?
...全文
1922 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenshouhong 2009-12-28
  • 打赏
  • 举报
回复
我也遇到这样的问题,引用别的类库时造成设计器无法加载页面,一直提示无法加载程序集,但是编译照样可以通过,程序运行时显示正常
RedErick 2009-04-05
  • 打赏
  • 举报
回复
Error 1 The tag 'Ca' does not exist in XML namespace 'clr-namespace:TestModel'. Line 7 Position 10. C:\Data\Visual Studio 2008\Projects\MyWpfTest\MyWpfTest\Page3.xaml 7 10 MyWpfTest
老兄帮忙仔细看看
cppfaq 2009-04-04
  • 打赏
  • 举报
回复
没什么特别的,一样来引用:
[code=XAML]
<Page x:Class="WpfApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TestModel="clr-namespace:TestModel"
Title="Page1" Loaded="Page_Loaded">
<Page.Resources>
<TestModel:Ca x:Key="Ca1"/>
</Page.Resources>
<Grid Name="gRoot">
</Grid>
</Page>

[/code]

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧