A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/binding-sources-overview below:

Binding sources overview - WPF

In data binding, the binding source object refers to the object you obtain data from. This article discusses the types of objects you can use as the binding source, like .NET CLR objects, XML, and DependencyObject objects.

Binding source types

Windows Presentation Foundation (WPF) data binding supports the following binding source types:

Implement a binding source on your objects

Your CLR objects can become binding sources. There are a few things to be aware of when implementing a class to serve as a binding source.

Provide change notifications

If you're using either OneWay or TwoWay binding, implement a suitable "property changed" notification mechanism. The recommended mechanism is for the CLR or dynamic class to implement the INotifyPropertyChanged interface. For more information, see How to: Implement Property Change Notification (.NET Framework).

There are two ways to notify a subscriber of a property change:

If your binding source implements one of these notification mechanisms, target updates happen automatically. If for any reason your binding source doesn't provide the proper property changed notifications, you can use the UpdateTarget method to update the target property explicitly.

Other characteristics

The following list provides other important points to note:

Entire objects as a binding source

You can use an entire object as a binding source. Specify a binding source by using the Source or the DataContext property, and then provide a blank binding declaration: {Binding}. Scenarios in which this is useful include binding to objects that are of type string, binding to objects with multiple properties you're interested in, or binding to collection objects. For an example of binding to an entire collection object, see How to Use the Master-Detail Pattern with Hierarchical Data (.NET Framework).

You may need to apply custom logic so that the data is meaningful to your bound target property. The custom logic may be in the form of a custom converter or a DataTemplate. For more information about converters, see Data conversion. For more information about data templates, see Data Templating Overview (.NET Framework).

Collection objects as a binding source

Often, the object you want to use as the binding source is a collection of custom objects. Each object serves as the source for one instance of a repeated binding. For example, you might have a CustomerOrders collection that consists of CustomerOrder objects, where your application iterates over the collection to determine how many orders exist and the data contained in each order.

You can enumerate over any collection that implements the IEnumerable interface. However, to set up dynamic bindings so that insertions or deletions in the collection update the UI automatically, the collection must implement the INotifyCollectionChanged interface. This interface exposes an event that must be raised whenever the underlying collection changes.

The ObservableCollection<T> class is a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface. The individual data objects within the collection must satisfy the requirements described in the preceding sections. For an example, see How to Create and Bind to an ObservableCollection (.NET Framework). Before you implement your own collection, consider using ObservableCollection<T> or one of the existing collection classes, such as List<T>, Collection<T>, and BindingList<T>, among many others.

When you specify a collection as a binding source, WPF doesn't bind directly to the collection. Instead, WPF actually binds to the collection's default view. For information about default views, see Using a default view.

If you have an advanced scenario and you want to implement your own collection, consider using the IList interface. This interface provides a non-generic collection of objects that can be individually accessed by index, which can improve performance.

Permission requirements in data binding

Unlike .NET Framework, .NET runs with full-trust security. All data binding runs with the same access as the user running the application.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4