Linking data with Silverlight

If I want to bind a collection to some form of listing management in Silverlight. The only way to do this is to make the base objects in the implementation of the INotifyPropertyChanged collection and for the collection to be Observablecollection?

If I used some third-party object, for example, returned by a web service, would I have to wrap it or map it to what INotifyPropertyChanged implements?

+4
source share
4 answers

No, once you add a service link to a silverlight project in Visual Studio, you can right-click it and configure it to use an ObservableCollection (the default is the default)

In addition, a default service reference will ensure that the returned service types already implement INotifyPropertyChanged.

+5
source

You can bind the list to any IEnumerable collection or to a simple control for any property of the object. The downside is that you don't get chnage notifications if items are added to the list or properties are changed. So it depends on your application if this is a problem or not.

+1
source

As Maurice said, you can bind to any collection (even IEnumerable), and the binding will work, but you will not receive notification of changes. Note, however, that you do not need to use an ObservableCollection, anything that implements INotifyCollectionChanged will work (although an ObservableCollection is the simplest).

It is not necessary that the objects within the collection implement INotifyPropertyChanged, but if they do, you will receive notifications with every single change.

+1
source

To be clear, you can snap OneTime to any object. If you want to bind OneWay or TwoWay , the object will support one of these interfaces. As already mentioned, creating a Service Reference does this for you for objects delivered via webservice. However, if for some reason you still need to create a Bindable object from an inherited class, you can implement a converter that implements IValueConverter, and then use it to "wrap" your old object in Bindable one live this:

<UserControl> <UserControl.Resources> <local:FooToBindableFooConverter x:Key="BindableFooConverter"/> </UserControl.Resources> <TextBlock Text="{Binding FooInstance, Converter={StaticResource BindableFooConverter}}"/> </UserControl> 

The converters are very powerful and can solve many of the problems "I need X, but I have Y."

0
source

Source: https://habr.com/ru/post/1277075/


All Articles