简体   繁体   中英

How to refresh the UI in a metro app?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM