English 中文(简体)
故事如何。 目标日期?
原标题:How is Storyboard.TargetName implemented?

I m 建立一个需要参考另一种控制的习俗工具包。 它与故事板非常相似。 目标会奏效。 现在,我介绍了我如何获得指标参考的自我执行,例如(我的目标永远是工具包的家长):

public object FindTarget(string targetName)
{
    var target = default(object);
    FrameworkElement item = this;
    while ((item = item.Parent as FrameworkElement) != null && target == null)
        target = item.FindName(targetName);
    return target;
}

我的问题是,有办法在框架中做到这一点? 这似乎是一项足够共同的任务。

Edit:

上面的算法并不实际用于工具包,因为其父母的财产总是无效。 我假定工具Tips是基于Popups,这就是为什么父母无效的原因。

问题回答

您可以采用推广方法,从你想要的任何地方可见:

public static object GetElementByName(this FrameworkElement baseElement, string name) 
    {
        object target = null;

        FrameworkElement item = baseElement;
        while ((item = item.Parent as FrameworkElement) != null && target == null)
            target = item.FindName(name);

        return target;
    }

After this you are able to call this method on any FrameworkElement. Although you should be aware of the fact that FindName will not work for names defined in Templates.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签