开发者

Silverlight DataBinding Loading Animation

Is there an event somewhere in the Silverlight control model that is raised once an item i开发者_高级运维s databound? I am binding at design time to a large amount of data and would like to display an animation until the databinding is complete.


There is no specific event that is fired when databinding is completed. Your best bet would probably be to key off of the FrameworkElement.LayoutUpdated event. This is the last event in the lifecycle before a control is ready for user interaction. However, this event will continue to be raised many more times due to property changes, size changes, and explicit calls to UpdateLayout() or InvalidateArrange(). Therefore you will have to add some extra logic to make sure that the LayoutUpdated event warrants stopping/hiding your animation, such as only doing it the first time or if you are sure the event was fired due to a change in databinding.

If the control is actually your own custom control and you are binding to custom DependencyProperties on that control then you could raise your own event on the PropertyChangedCallbacks for each of the properties to signal that they have been updated via databinding.


Here's what I do:

private object lastDataContext;
private void MyClass_Loaded(object sender, RoutedEventArgs e)
{
    if (DataContext != lastDataContext)
    {
        perform_onetime_operation();
        lastDataContext = DataContext;
    }
}

That way perform_onetime_operation will get called not just the first time databinding happens, but any time that the DataContext changes meaning that data is re-bound.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜