我是Silverlight的新手。
我已经创建了一种母版页,它使用一个页面和一个加载内容的框架。当我同时处理多个内容时(只显示了一个,但我想保持之前打开的状态),我设置了UserControls属性而不是导航方法。这样,我就可以为UserControl分配一个UserControl(已经创建,而不是一个新的,因为它将使用带有Uri的导航)。
现在我想拍摄一张图片,当它的内容发生变化时,从框架中显示here。如果我在设置内容时立即执行此操作,UserControl将不会显示在图片中,因为这需要几秒钟的时间。框架有导航的事件,但它不会触发属性内容(它只是在使用导航方法时触发,顾名思义)。
我怎么知道什么时候加载了新内容?
如果有用的话,我正在使用Silverligh5。
发布于 2012-04-18 02:27:08
我有一个解决方案,但我真的不喜欢它,所以我仍然在寻找其他方法。
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());
}
}https://stackoverflow.com/questions/10179829
复制相似问题