开发者

Silverlight: FrameworkElement.FindName() not finding the control when it's not "visible" in the browser window

开发者 https://www.devze.com 2023-04-10 18:36 出处:网络
I\'m having an issue where by I\'m using the \"FindName()\" method of the FrameworkElement object to search for a child control of that element.

I'm having an issue where by I'm using the "FindName()" method of the FrameworkElement object to search for a child control of that element.

There's some interesting behavior that I've noticed and can't seem to figure out. If the user scrolls the browser window so that the control itself visibly is not shown anymore within the context of the window frame, then the "FindName()" does not return the element. However, if that control is visible wi开发者_如何学Gothin the window frame, it finds it fine.

Is this a known issue? Has anyone else run into this before?

I'm not talking about the Visibility property of the control either. The Visibility property is set to Visible.

Update I attempted to set VirtualizingStackPanel.VirtualizationMode="Standard" on the ListBox control (which is the container I'm searching) and it still did not find the control specified.


If i understand you correctly you are saying that when a control is scrolled out of the ViewPort of the application then even though it's visible property remains true, FrameworkElement.FindName("") cannot find it.

I assume you've worked through all the basics re: Xaml scoping etc. If you're adding controls dynamically are you sure you're walking from the correct parent element etc. If so:

Using RedGates Reflector we can see that FrameWorkElement.FindName is implemented as follows:

public object FindName(string name)
{
    return XcpImports.DependencyObject_FindName(this, name);
}

XcpImports.DependencyObject_FindName is implemented as

[SecuritySafeCritical]
internal static DependencyObject DependencyObject_FindName(DependencyObject referenceDO, string name)
{
    int num;
    IntPtr ptr;
    CheckThread();
    if (name == null)
    {
        throw new ArgumentNullException("name");
    }
    uint hr = FindNameNative(JoltHelper.Context, (uint) name.Length, name, referenceDO.NativeObject, out num, out ptr);
    GC.KeepAlive(referenceDO);
    if ((hr != 0) && (hr != 0x80004005))
    {
        throw Error.MarshalXresultAsException(hr);
    }
    return (DependencyObject) ConvertDO(ptr, num, true);
}

So unless you are encountering an exception I think the most interesting line is probably:

uint hr = FindNameNative(JoltHelper.Context, (uint) name.Length, name, referenceDO.NativeObject, out num, out ptr);

Which is stepping out into native code and defined via a dll import in XcpImports:

[DllImport("agcore", EntryPoint="FindName", CharSet=CharSet.Unicode)]
private static extern uint FindNameNative(IntPtr context, uint cString, [MarshalAs(UnmanagedType.LPWStr)] string name, IntPtr referenceObject, out int typeIndex, out IntPtr obj);

Not to be confused with Developers Express's AgCore.

This article on ZdNet (circa 2007) by Ed Burnette:

http://www.zdnet.com/blog/burnette/dissecting-silverlight/297

Says that:

agcore.dll (2.2M installed) - This is the core ActiveX control that is responsible for Silverlight rendering and events, including audio and video decoding.

It also says below that that:

npctrl.dll (460K) - A wrapper for agcore.dll that makes it run inside Firefox.

So my first question would be. Is your problem consistent in every browser? Perhaps it is a wrapper for agcore.dll in some browser/version that is the problem and not the core technology (agcore.dll) itself.


If you use a tool such a Silverlight Spy you can try and find the control by hand.

If it is not there it is probably in a virtualizing stackpanel.

0

精彩评论

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

关注公众号