2012-04-16 5 views
0

저는 Silverlight를 처음 사용했습니다.프레임 내용로드 됨 이벤트

콘텐츠가로드 된 프레임이있는 페이지를 사용하여 일종의 마스터 페이지를 만들었습니다. 내가 여러 UserControls 그 당시에 (하나만 표시됩니다,하지만 난 전에 열어 놓은 상태를 유지하고) 처리로 ContentControl 대신 Navigate 메서드를 설정 해요. 그렇게하면 UserControl을 할당 할 수 있습니다 (이미 생성되었으므로 Uri와 함께 UserControl에 대한 Navigate를 사용할 것입니다).

이제 콘텐츠가 변경되면 프레임에서 here으로 표시된 사진을 찍고 싶습니다. 내용을 설정할 때 즉시 작업을 수행하면 몇 초가 걸리기 때문에 그림에 UserControl이 표시되지 않습니다. 프레임에는 Navigated 이벤트가 있지만 속성 Content와는 작동하지 않습니다 (이름이 말하는대로 Navigate 메서드가 사용될 때 발생합니다).

새 콘텐츠가로드 된시기를 어떻게 알 수 있습니까?

은 내가 해결책을했습니다하지만 내가 정말 좋아하지 않습니다

답변

0

Silverligh 5를 사용하고, 그래서 여전히 다른 방법을 찾고 있어요 도움이된다면.

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