silverlight 在同一程序集下新建一个类文件应用控件问题

zwb65300297 2010-01-27 07:52:55
我在同一程序集下新建一个类文件
我想做一个创建默认控件模板的实例
代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SimpleButtonDemo
{
public class SimpleButton : ContentControl
{
public SimpleButton() { }
}
}

在XAML文件里
代码如下:
<UserControl x:Class="SimpleButtonDemo.MainPage"
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:custom="clr-namespace:SimpleButtonDemo; assembly=SimpleButtonDemo"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
<custom:SimpleButton>
<custom:SimpleButton.Template>
<ControlTemplate>
<Grid x:Name="RootElement">
<Rectangle x:Name="BodyElement" Width="200" Height="100"
Fill="Lavender" Stroke="Purple" RadiusX="16" RadiusY="16" />
<TextBlock Text="Click Me" HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</custom:SimpleButton.Template>
</custom:SimpleButton>

<custom:SimpleButton >sa</custom:SimpleButton>


</Grid>
</UserControl>


结果说这问题
The tag 'SimpleButton' does not exist in XML namespace 'clr-namespace:SimpleButtonDemo; assembly=SimpleButtonDemo'. D:\vs 2010 项目\SimpleButtonDemo\SimpleButtonDemo\MainPage.xaml
很郁闷我感觉我应用程序集一点问题都没啊
请高手们指点下
...全文
103 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jv9 2010-01-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zwb65300297 的回复:]
我找到问题了  xmlns:custom="clr-namespace:SimpleButtonDemo; assembly=SimpleButtonDemo"
中间不能有空格
xmlns:custom="clr-namespace:SimpleButtonDemo;assembly=SimpleButtonDemo"
这样就对了  郁闷

[/Quote]

:)格式要求很严格,解决就好~
zwb65300297 2010-01-28
  • 打赏
  • 举报
回复
我找到问题了 xmlns:custom="clr-namespace:SimpleButtonDemo; assembly=SimpleButtonDemo"
中间不能有空格
xmlns:custom="clr-namespace:SimpleButtonDemo;assembly=SimpleButtonDemo"
这样就对了 郁闷
jv9 2010-01-28
  • 打赏
  • 举报
回复
xmlns:custom="clr-namespace:SimpleButtonDemo; assembly=SimpleButtonDemo"

看看是否有这个类存在?删除自定义按钮,重新编译,然后重新添加命名空间试试。

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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