开发者

Why ImageBrush raises an error but still shows up normally?

I have a custom control with the following DependencyPorperty:

  public static readonly DependencyProperty MyImageProperty = DependencyProperty.Register(
      "MyImage",
     开发者_如何学运维 typeof(ImageSource),
      typeof(ImageButton), // that's my custom control class name
      new PropertyMetadata(null));

  public ImageSource MyImage
  {
      get { return (ImageSource)GetValue(MyImageProperty); }
      set { SetValue(MyImageProperty, value); }
  }

If I try the following code:

        <Border Name="btnBorder" Height="30">
                <Border.Background>
                    <ImageBrush ImageSource="{Binding Path=MyImage}"  />
                </Border.Background>
        </Border>

I always have the following error in the Visual Studio 2010 Output window:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=MyImage; DataItem=null; target element is 'ImageBrush' (HashCode=47992654); target property is 'ImageSource' (type 'ImageSource')

but still the application runs fine and the image is loaded normally, no exceptions.

But if I do the following:

<Image Name="btnImage" Source="{Binding MyImage}" />

there are no errors and again application works ok.

Why is this error for ImageBrush? Am I doing something wrong with it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜