【发布时间】:2009-01-07 03:47:34
【问题描述】:
我有一个公开 ImageSource 类型属性的用户控件。我想在 Blend 中公开这个属性,以便我可以在 Blend 中编辑它,而不是在代码中指定图像。
根据我在 Google 上搜索到的内容,我添加了一个依赖属性,并指定了适当的属性以在 Blend 中公开该属性。
我可以在那里看到它,并对其进行编辑(作为文本字段)。我想要做的是有一个可用图像资源的下拉列表,以及一个用于加载另一个图像的浏览按钮。换句话说,我希望它的行为类似于 'Image' 控件的 'Source' 属性。
edit顺便说一句,我注意到公开 Alignment 或 Margin 属性的行为符合预期,只是图像不起作用。我真的被困在这个问题上,希望能得到帮助!
我当前的代码如下:
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(SmartButton));
[Category("Appearance")]
[Bindable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set
{
SetValue(ImageSourceProperty, value);
this.BackgroundImage.Source = value;
}
}
【问题讨论】:
标签: wpf user-controls expression-blend dependency-properties