0

我有一个用户控件公开了ImageSource类型的属性。我想在Blend中公开此属性,以便我可以在Blend中对其进行编辑,而不是在代码中指定图像。在UserControl中公开ImageSource属性以用于混合

基于我谷歌搜索,我已经添加了一个依赖属性,并指定适当的属性来公开Blend属性。

我可以在那里看到它并编辑它(作为文本字段)。我想要做的是有一个可用图像资源的下拉列表,以及一个用于加载另一个图像的浏览按钮。换句话说,我希望它的行为像'图像'控件的'源'属性。

编辑就像旁边一样,我注意到暴露对齐或边距属性的行为与预期的一样,它似乎只是图像不起作用。我真的被困在这一个,并会感谢帮助!

我当前的代码看起来像:

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; 
    } 
} 

回答

1

我一直在努力几乎一模一样这个问题

在我的情况下,我有(减去混合,再加上在XAML中的ControlTemplate使用属性。)通过将ImageSource更改为BitmapSource来获得它的工作。 ImageSource是抽象的,BitmapSource扩展了ImageSource。

但是,有些事情对此感觉不对。 Image.Source的类型是ImageSource。无论它是否是抽象的,我似乎应该能够使用ImageSource类型的DependencyProperty。

因此,对于我自己的情况,我已经与BitmapSource合作,但我仍在调查。

编辑:希望你不介意答案差不多一年后,你问,+/- 12小时。 ;)

EDIT2:乔治,我还没有得到这为我与ImageSource使用工作:

public static readonly DependencyProperty SourceProperty = 
    Image.SourceProperty.AddOwner(typeof(MyCustomButton)); 
public ImageSource Source 
{ 
    get { return (ImageSource)GetValue(SourceProperty); } 
    set { SetValue(SourceProperty, value); } 
} 
+0

不,谢谢你的提示!下次我在Blend时我会尝试一下。 – 2010-01-10 05:38:46

相关问题