自定义依赖项属性 Custom Dependency Property

Error_Code 2009-04-21 03:13:36

我有一个3D翻转的Usercontrol.
现在需要给它设置一个依赖项属性, 从XAML里设置前景空间,也就是翻转之后的正面
以下是我的代码

public static DependencyProperty FrontContentProperty
= DependencyProperty.Register(
"FrontSideContentProperty",
typeof(UIElement),
typeof(FlipPanel),//FlipPanel是此Usercontrol的类名
new UIPropertyMetadata(
null,
new PropertyChangedCallback(OnFrontSideContentChanged)),
new ValidateValueCallback(ContentValueValidate)
);
public UIElement FrontSideContent
{
get
{
return (UIElement)GetValue(FrontContentProperty);
}
set
{
SetValue(FrontContentProperty, value);
}
}

private static void OnFrontSideContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
FlipPanel target = o as FlipPanel;
target.FrontContentBorder.Child = (UIElement)e.NewValue; // 这是最终目的 把value设置到border的child属性
}

usercontrol编译通过,, 添加到window里出现下面的错误:

无法创建在程序集“xxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”中定义的“FlipPanel”的实例。 调用的目标发生了异常。 标记文件“xxx;component/mainwindow.xaml”中行29位置 10 的对象“grid”处的错误。

如果把以上code注释掉 则没有任何问题..
但是不设置Dependency Property就不能用到ElementName``和转换器~?

who can help me ? how to create a custom Dependency Property?

this topic is grate http://geekswithblogs.net/thibbard/archive/2008/04/22/wpf-custom-control-dependency-property-gotcha.aspx
but for me, it doesnt work, I have no idea.
...全文
126 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,347

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET技术前瞻
社区管理员
  • .NET技术前瞻社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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