次の方法で共有


Silverlight: Why do I get 0x8000ffff when using WriteableBitmap on an Element

I'm working on a WP7 library which helps analyze your VisualTree and to provide a visual aid, I take WriteableBitmap snaps of the elements. Unfortunately I (seemingly) randomly encounter the following exception:

 

 A first chance exception of type 'System.Exception' occurred in System.Windows.dll

When digging into the exception you may find that the error is actually a HRESULT which is being bubbled up from the lower native layer:

 

 E_UNEXPECTED (0x8000ffff) 

What's going on?

You guessed it - this isn't random! In fact, this only happens on completely obscured (or off screen) elements which have never had a chance to render. In this case when you try to take a WriteableBitmap snap, instead of it forcing the control to render, it simply fails. This will hit you in the case of any element that has always been obscured. As soon as the element is unobscured it will be good to go (so you could do some VisualTree manipulation if you *really* needed to grab that shot).

Comments

  • Anonymous
    December 21, 2010
    Could you elaborate on how to do the VisualTree manipulation in order to get the shot without rendering the control? I do really need to grab the shot :)

  • Anonymous
    January 05, 2011
    @Paul You need to apply an action to your element to force it be drawn - for example, bring it into view or set its Visibility accordingly. Hope that helps...