首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Frame ContentLoaded事件

Frame ContentLoaded事件
EN

Stack Overflow用户
提问于 2012-04-17 02:47:49
回答 1查看 390关注 0票数 0

我是Silverlight的新手。

我已经创建了一种母版页,它使用一个页面和一个加载内容的框架。当我同时处理多个内容时(只显示了一个,但我想保持之前打开的状态),我设置了UserControls属性而不是导航方法。这样,我就可以为UserControl分配一个UserControl(已经创建,而不是一个新的,因为它将使用带有Uri的导航)。

现在我想拍摄一张图片,当它的内容发生变化时,从框架中显示here。如果我在设置内容时立即执行此操作,UserControl将不会显示在图片中,因为这需要几秒钟的时间。框架有导航的事件,但它不会触发属性内容(它只是在使用导航方法时触发,顾名思义)。

我怎么知道什么时候加载了新内容?

如果有用的话,我正在使用Silverligh5。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-18 02:27:08

我有一个解决方案,但我真的不喜欢它,所以我仍然在寻找其他方法。

代码语言:javascript
复制
public class CustomFrame : Frame
{
    private readonly RoutedEventHandler loadedDelegate;

    public static readonly DependencyProperty UseContentInsteadNavigationProperty =
        DependencyProperty.Register("UseContentInsteadNavigation", typeof (bool), typeof (CustomFrame), new PropertyMetadata(true));

    public bool UseContentInsteadNavigation
    {
        get { return (bool)GetValue(UseContentInsteadNavigationProperty); }
        set { SetValue(UseContentInsteadNavigationProperty, value); }
    }

    public CustomFrame()
    {
        this.loadedDelegate = this.uc_Loaded;
    }

    public new object Content
    {
        get { return base.Content; }
        set
        {
            if (UseContentInsteadNavigation)
            {
                FrameworkElement fe = (FrameworkElement)value;
                fe.Loaded += loadedDelegate;
                base.Content = fe;
            }
            else
            {
                base.Content = value;
            }
        }
    }

    void uc_Loaded(object sender, RoutedEventArgs e)
    {
        ((UserControl)sender).Loaded -= loadedDelegate;
        OnContentLoaded();
    }

    public delegate void ContentLoadedDelegate(Frame sender, EventArgs e);
    public event ContentLoadedDelegate ContentLoaded;

    private void OnContentLoaded()
    {
        if (ContentLoaded != null)
            ContentLoaded(this, new EventArgs());
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10179829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档