How to refresh the UI in a metro app?

对着背影说爱祢 提交于 2019-12-25 05:31:03

问题


I'm using this code in a XAML page:

<TextBox ItemsSource="{Binding Posters, Converter={StaticResource collectionToFirstElementConverter}, Mode=TwoWay}" />

Posters is an ObsevableCollection and I'm using a converter where takes the collection and gets the first element of it.

As I'm using async procedures, where the textbox receives the object, this one has no elements (Count=0), and calls the converter.

I'm trying to update the textbox everytime the property add new elements, but not calls the converter.

I remember that in Silverlight or WPF, exists SourceTrigger or UpdatePropertyChanged, but in WinRT I can't see this mode.


回答1:


The easiest way to achieve that would be to modify your view model containing the Posters property accordingly. I can see two ways to go about it (both asuming that your view model implements INotifyPropertyChanged):

  • Add an event handler to Posters.CollectionChanged and inside it raise INotifyPropertyChanged.PropertyChanged for Posters.
  • Add another property FirstPoster returning the value of the first element in Posters. In the view model add an event handler to Posters.CollectionChanged and inside it raise INotifyPropertyChanged.PropertyChanged for FirstPoster. This way you don't even need the converter.

I personally like the second approach better.



来源:https://stackoverflow.com/questions/11111432/how-to-refresh-the-ui-in-a-metro-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!