2012-04-16 10 views
0

私はSilverlightで初めてです。フレームコンテンツの負荷イベント

私は、コンテンツが読み込まれるフレームを持つページを使用して一種のマスターページを作成しました。私はその時点で複数のUserControlsを扱うので(1つしか表示されませんが、前に開いた状態を保持したい)、Navigateメソッドの代わりにContentプロパティを設定しています。そうすれば、私はUserControlを割り当てることができます(すでに作成されていますが、UserControlにUriでNavigateを使用するように新しいものは作成されません)。

ここでは、コンテンツが変更されたときにフレームからhereのように写真を撮りたいと思います。コンテンツが設定されたときに直ちにそれを行うと、UserControlは数秒かかるので画像に表示されません。フレームにはNavigatedイベントがありますが、プロパティContentで起動しません(Navigateメソッドが使用されたときに起動します)。

新しいコンテンツがいつ読み込まれるかわかりますか?

それは私がSilverligh 5に

答えて

0

を使用しているのに役立ちます場合は、私は解決策をしましたが、私はそれを本当に好きではないので、私はまだ他の方法を探しています。

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()); 
    } 
}