自定义控件的属性问题

aa6965921 2010-03-06 12:55:39
public double X
{
get { return (double)GetValue(XProperty); }
set { SetValue(XProperty, value); }
}
public static readonly DependencyProperty XProperty = DependencyProperty.Register(
"X", //属性名
typeof(double), //属性类型
typeof(QX), //属性主人类型
null);
/// <summary>
/// 精灵Y坐标(关联属性)
/// </summary>
public double Y
{
get { return (double)GetValue(YProperty); }
set { SetValue(YProperty, value); }
}
public static readonly DependencyProperty YProperty = DependencyProperty.Register(
"Y",
typeof(double),
typeof(QX),
null);
public BitmapImage Source { get; set; } //图片地址

我这里 写错了吗 我每次用这些属性的时候 页面会无法显示
...全文
40 2 打赏 收藏 转发到动态 举报
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanbei 2010-03-12
  • 打赏
  • 举报
回复
不太明白什么意思。我看你下面有个属性是想动态绑定一个图片?你是说图片显示不出来?

如果是想动态绑定图片的话,下面是个例子

[code=XAML]
<Image x:Name="loadingImage" Source="{TemplateBinding ButtonImage}"/>
[/code]
这是

public class CustomButton:Button
{
public CustomButton()
{
this.DefaultStyleKey = typeof(CustomButton);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}

public static readonly DependencyProperty ButtonImageProperty = DependencyProperty.Register("ButtonImage", typeof(ImageSource), typeof(CustomButton), null);

public ImageSource ButtonImage
{
get { return (ImageSource)GetValue(ButtonImageProperty); }
set { SetValue(ButtonImageProperty, value); }
}
}


jv9 2010-03-10
  • 打赏
  • 举报
回复
看起来没错,页面无法显示有错误提示么?或者你可以debug一下。
相关推荐

8,707

社区成员

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