Kris' Blog

RSS feed

The operation completed successfully.

The stacktrace says it all.

System.Runtime.InteropServices.COMException (0x80070000): The operation completed successfully. (Exception from HRESULT: 0x80070000)
   at MS.Internal.HRESULT.Check(Int32 hr)
   at System.Windows.Media.SafeProfileHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
   at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
   at System.Runtime.InteropServices.SafeHandle.Finalize()

We made this go away by calling GC.WaitForPendingFinalizers() but this can cause deadlocks in WPF since some Finalize() methods use Dispatcher.Invoke().


Square inscribed on a wedge (Updated)

My first xbap (works in IE only with .Net 3.0).

public static Rect GetSquareInscribedOnWedge(double a, double r, Point center)
{
    double t = Math.Tan(a/2);
    double x = Math.Sqrt(r*r/(1/(t*t) + 4/t + 5));
    return new Rect(center.X - x, center.Y - x/t - 2*x, 2*x, 2*x);
}

I’m too tired to say anything about it. I’ll write more later.


Visibility.Visible != IsVisible

Today, Robert and I spent a while trying to figure out why we couldn’t give focus to a TextBox we added dynamically. Calling textBox.Focus() was always returning false, yet we could click on it to focus.

Reading the WPF focus overview, Focus() returns false if either IsEnabled, IsVisible or Focusable are false — well it defaults to being enabled, visible and focusable so why isn’t it working?

IsVisible is calculated during the Layout pass, which isn’t going to happen on this dispatcher operation. During this time, textBox.Visibility will return Visibility.Visible and textBox.IsVisible will return false.

Determination of the IsVisible value takes all factors of layout into account. In contrast, Visibility, which is a settable property, only indicates the intention to programmatically make an element visible or invisible.

textBox = new TextBox();
AddChild(textBox);
// textBox.IsVisible == false
textBox.UpdateLayout();
// textBox.IsVisible == true
textBox.Focus() // returns true

In general, read-only properties, especially dependency properties registered as read-only, will need an UpdateLayout (I wouldn’t do that a lot) or you will need to BeginInvoke your work on the Dispatcher to wait for layout.