- Практическое руководство. Сортировка и группировка данных с помощью представления в XAML How to: Sort and Group Data Using a View in XAML
- Пример Example
- Multi Binding Class
- Definition
- Remarks
- Constructors
- Properties
- Methods
- Explicit Interface Implementations
- Binding Class
- Definition
- Remarks
- XAML Attribute Usage
- XAML Values
- Constructors
- Fields
- Properties
- Attached Properties
- Methods
- Attached Events
Практическое руководство. Сортировка и группировка данных с помощью представления в XAML How to: Sort and Group Data Using a View in XAML
В этом примере показано, как создать представление коллекции данных в Язык XAML Extensible Application Markup Language (XAML) . This example shows how to create a view of a data collection in Язык XAML Extensible Application Markup Language (XAML) . Представления обеспечивают функциональные возможности группирования, сортировки, фильтрации и понятия текущего элемента. Views allow for the functionalities of grouping, sorting, filtering, and the notion of a current item.
Пример Example
В следующем примере статический ресурс с именем Places определяется как коллекция объектов Place , в которых каждый объект- место состоит из названия города и состояния. In the following example, the static resource named places is defined as a collection of Place objects, in which each Place object is consisted of a city name and the state. Префикс src сопоставляется с пространством имен, в котором определены источники данных . The prefix src is mapped to the namespace where the data source Places is defined. Префикс SCM сопоставляется с «clr-namespace:System.ComponentModel;assembly=WindowsBase» и dat Maps «clr-namespace:System.Windows.Data;assembly=PresentationFramework» . The prefix scm maps to «clr-namespace:System.ComponentModel;assembly=WindowsBase» and dat maps to «clr-namespace:System.Windows.Data;assembly=PresentationFramework» .
В следующем примере создается представление коллекции данных, которая сортируется по названию города и группируются по состоянию. The following example creates a view of the data collection that is sorted by the city name and grouped by the state.
Представление может быть источником привязки, как показано в следующем примере: The view can then be a binding source, as in the following example:
Для привязок к XML-данным, определенным в XmlDataProvider ресурсе, перед именем XML следует указывать символ @. For bindings to XML data defined in an XmlDataProvider resource, precede the XML name with an @ symbol.
Multi Binding Class
Definition
Describes a collection of Binding objects attached to a single binding target property.
Remarks
You can specify multiple bindings in a MultiBinding object. When you use the MultiBinding object with a converter, it produces a final value for the binding target based on the values of those bindings. For example, color might be computed from red, blue, and green values, which can be values from the same or different binding source objects. When a value moves from the target to the sources, the target property value is translated to a set of values that are fed back into the bindings.
The values of the Mode and UpdateSourceTrigger properties determine the functionality of the MultiBinding and are used as the default values for all the bindings in the collection unless an individual binding overrides these properties. For example, if the Mode property on the MultiBinding object is set to TwoWay, then all the bindings in the collection are considered TwoWay unless you set a different Mode value on one of the bindings explicitly. For more information, see the Binding.Mode and Binding.UpdateSourceTrigger properties.
MultiBinding currently supports only objects of type Binding and not MultiBinding or PriorityBinding.
Constructors
Initializes a new instance of the MultiBinding class.
Properties
Gets or sets the name of the BindingGroup to which this binding belongs.
(Inherited from BindingBase)
Gets the collection of Binding objects within this MultiBinding instance.
Gets or sets the converter to use to convert the source values to or from the target value.
Gets or sets the CultureInfo object that applies to any converter assigned to bindings wrapped by the MultiBinding or on the MultiBinding itself.
Gets or sets an optional parameter to pass to a converter as additional information.
Gets or sets the amount of time, in milliseconds, to wait before updating the binding source after the value on the target changes.
(Inherited from BindingBase)
Gets or sets the value to use when the binding is unable to return a value.
(Inherited from BindingBase)
Gets or sets a value that indicates the direction of the data flow of this binding.
Gets or sets a value that indicates whether to raise the SourceUpdated event when a value is transferred from the binding target to the binding source.
Gets or sets a value that indicates whether to raise the TargetUpdated event when a value is transferred from the binding source to the binding target.
Gets or sets a value that indicates whether to raise the Error attached event on the bound element.
Gets or sets a string that specifies how to format the binding if it displays the bound value as a string.
(Inherited from BindingBase)
Gets or sets the value that is used in the target when the value of the source is null .
(Inherited from BindingBase)
Gets or sets a handler you can use to provide custom logic for handling exceptions that the binding engine encounters during the update of the binding source value. This is only applicable if you have associated the ExceptionValidationRule with your MultiBinding object.
Gets or sets a value that determines the timing of binding source updates.
Gets or sets a value that indicates whether to include the DataErrorValidationRule.
Gets or sets a value that indicates whether to include the ExceptionValidationRule.
Gets or sets a value that indicates whether to include the NotifyDataErrorValidationRule.
Gets the collection of ValidationRule objects for this instance of MultiBinding.
Methods
Determines whether the specified object is equal to the current object.
(Inherited from Object)
Serves as the default hash function.
(Inherited from Object)
Gets the Type of the current instance.
(Inherited from Object)
Creates a shallow copy of the current Object.
(Inherited from Object)
Returns an object that should be set on the property where this binding and extension are applied.
(Inherited from BindingBase)
Indicates whether the Bindings property should be persisted.
Returns a value that indicates whether serialization processes should serialize the effective value of the FallbackValue property on instances of this class.
(Inherited from BindingBase)
Returns a value that indicates whether the TargetNullValue property should be serialized.
(Inherited from BindingBase)
Indicates whether the ValidationRules property should be persisted.
Returns a string that represents the current object.
(Inherited from Object)
Explicit Interface Implementations
Adds a child object.
Adds the text content of a node to the object.
Binding Class
Definition
Provides high-level access to the definition of a binding, which connects the properties of binding target objects (typically, WPF elements), and any data source (for example, a database, an XML file, or any object that contains data).
Remarks
Windows Presentation Foundation (WPF) data binding provides a simple and consistent way for applications to present and interact with data. Data binding enables you to synchronize the values of the properties of two different objects.
To establish a binding, use the Binding class or one of the other classes that inherit BindingBase. Regardless of what object you are binding and the nature of your data source, each binding follows the model illustrated by the following figure.
The figure demonstrates the following fundamental WPF data binding concepts.
Each binding typically has these four components: a binding target object, a target property, a binding source, and a Path to the value in the binding source to use. For example, if you want to bind the content of a TextBox to the Name property of an Employee object, your target object is the TextBox, the target property is the Text property, the value to use is Name, and the source object is the Employee object.
The target property must be a dependency property. This also means that you cannot bind a field. Most properties of UIElement objects are dependency properties and most dependency properties, except read-only ones, support data binding by default. (Only DependencyObject types can define dependency properties and all UIElement objects derive from DependencyObject.)
Although not specified in the figure, it should be noted that the binding source object is not restricted to being a custom CLR object. WPF data binding supports data in the form of CLR objects and XML. To provide some examples, your binding source may be a UIElement, any list object, a CLR object that is associated with ADO.NET data or Web Services, or an XmlNode that contains your XML data.
Use the Mode property to specify the direction of the data flow. To detect source changes in one-way or two-way bindings, the source must implement a suitable property change notification mechanism such as INotifyPropertyChanged. For an example, see How to: Implement Property Change Notification. The UpdateSourceTrigger property specifies the timing of source updates. For more information, see «Basic Data Binding Concepts» in Data Binding Overview.
XAML Attribute Usage
XAML Values
declaration
Zero or more attribute-assignment clauses separated by commas (,). For more information, see Binding Markup Extension or Binding Declarations Overview.
Constructors
Initializes a new instance of the Binding class.
Initializes a new instance of the Binding class with an initial path.
Fields
Used as a returned value to instruct the binding engine not to perform any action.
Used as the PropertyName of PropertyChangedEventArgs to indicate that an indexer property has changed.
Identifies the SourceUpdated attached event.
Identifies the TargetUpdated attached event.
Identifies the XmlNamespaceManager attached property.
Properties
Gets or sets opaque data passed to the asynchronous data dispatcher.
Gets or sets the name of the BindingGroup to which this binding belongs.
(Inherited from BindingBase)
Gets or sets a value that indicates whether to evaluate the Path relative to the data item or the DataSourceProvider object.
Gets or sets the converter to use.
Gets or sets the culture in which to evaluate the converter.
Gets or sets the parameter to pass to the Converter.
Gets or sets the amount of time, in milliseconds, to wait before updating the binding source after the value on the target changes.
(Inherited from BindingBase)
Gets or sets the name of the element to use as the binding source object.
Gets or sets the value to use when the binding is unable to return a value.
(Inherited from BindingBase)
Gets or sets a value that indicates whether the Binding should get and set values asynchronously.
Gets or sets a value that indicates the direction of the data flow in the binding.
Gets or sets a value that indicates whether to raise the SourceUpdated event when a value is transferred from the binding target to the binding source.
Gets or sets a value that indicates whether to raise the TargetUpdated event when a value is transferred from the binding source to the binding target.
Gets or sets a value that indicates whether to raise the Error attached event on the bound object.
Gets or sets the path to the binding source property.
Gets or sets the binding source by specifying its location relative to the position of the binding target.
Gets or sets the object to use as the binding source.
Gets or sets a string that specifies how to format the binding if it displays the bound value as a string.
(Inherited from BindingBase)
Gets or sets the value that is used in the target when the value of the source is null .
(Inherited from BindingBase)
Gets or sets a handler you can use to provide custom logic for handling exceptions that the binding engine encounters during the update of the binding source value. This is only applicable if you have associated an ExceptionValidationRule with your binding.
Gets or sets a value that determines the timing of binding source updates.
Gets or sets a value that indicates whether to include the DataErrorValidationRule.
Gets or sets a value that indicates whether to include the ExceptionValidationRule.
Gets or sets a value that indicates whether to include the NotifyDataErrorValidationRule.
Gets a collection of rules that check the validity of the user input.
Gets or sets an XPath query that returns the value on the XML binding source to use.
Attached Properties
Gets or sets the XmlNamespaceManager used to perform namespace-aware XPath queries in XML bindings.
Methods
Adds a handler for the SourceUpdated attached event.
Adds a handler for the TargetUpdated attached event.
Determines whether the specified object is equal to the current object.
(Inherited from Object)
Serves as the default hash function.
(Inherited from Object)
Gets the Type of the current instance.
(Inherited from Object)
Returns an XML namespace manager object used by the binding attached to the specified object.
Creates a shallow copy of the current Object.
(Inherited from Object)
Returns an object that should be set on the property where this binding and extension are applied.
(Inherited from BindingBase)
Removes a handler for the SourceUpdated attached event.
Removes a handler for the TargetUpdated attached event.
Sets a namespace manager object used by the binding attached to the provided element.
Returns a value that indicates whether serialization processes should serialize the effective value of the FallbackValue property on instances of this class.
(Inherited from BindingBase)
Indicates whether the Path property should be persisted.
Indicates whether the Source property should be persisted.
Returns a value that indicates whether the TargetNullValue property should be serialized.
(Inherited from BindingBase)
Indicates whether the ValidationRules property should be persisted.
Returns a string that represents the current object.
(Inherited from Object)
Attached Events
Occurs when a value is transferred from the binding target to the binding source, but only for bindings with the NotifyOnSourceUpdated value set to true .
Occurs when a value is transferred from the binding source to the binding target, but only for bindings with the NotifyOnTargetUpdated value set to true .