How to invalidate page to enforce rendering again?
I have a page in my windows phone 7 app. This page sets it's background color to a StaticResource which is dynamically added based on a settings option.
Now the problem is this: Let's say page is now white, I go to settings and choose background black from this page and click OK to go back (and of course reset static resources on App.xaml). When I go back to main page because application has this page already on memory it still will have white background.
I can confirm that settings is saved correctly because when I exit and come back it works perfectly.How can I invalidate rendering state of a silverlight page? Or maybe how can I tell silverlight don't keep page on navigation.back() and always create a fresh version?开发者_StackOverflow中文版
I found some InvalidateXXX() method on UIElement but they seemed irrelevant.
Thanks
I am guessing you are removing and re-adding the App resource? If so, the StaticResource binding is still referencing the previous instance of that named brush from App.xaml. I gather StaticResource bindings do no respond to a change of key, only to INotifyPropertyChanged events.
Try changing the color value of the existing brush resource instead of replacing the brush e.g.:
(Application.Current.Resource["myColor"] as SolidColorBrush).Color = Colors.Red;
The Color property of a brush is a dependency property, so the change should update everywhere.
*Note: I can only test this with SL and not WP7 as the machine here is Win server 2003
精彩评论