Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Attribute (XElement dynamic property)
description: Learn how the XElement.Attribute property uses an indexer to retrieve the attribute instance that corresponds to the specified expanded name.
ms.date: 10/22/2019
ms.topic: reference
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: How-to articles for data binding
description: Review a list of data binding how-to topics describing how to use data binding to bind elements to data from a variety of data sources.
ms.date: "03/30/2017"
f1_keywords:
- "AutoGeneratedOrientationPage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The WPF data templating model provides you with great flexibility to define the
### Without a DataTemplate
Without a <xref:System.Windows.DataTemplate>, our <xref:System.Windows.Controls.ListBox> currently looks like this:

![Data templating sample screenshot](./media/datatemplatingintro-fig1.png "DataTemplatingIntro_fig1")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox displaying the string representation SDKSample.Task for each source object.](./media/datatemplatingintro-fig1.png "DataTemplatingIntro_fig1")

What's happening is that without any specific instructions, the <xref:System.Windows.Controls.ListBox> by default calls `ToString` when trying to display the objects in the collection. Therefore, if the `Task` object overrides the `ToString` method, then the <xref:System.Windows.Controls.ListBox> displays the string representation of each source object in the underlying collection.

Expand All @@ -47,7 +47,7 @@ The WPF data templating model provides you with great flexibility to define the

Then the <xref:System.Windows.Controls.ListBox> looks like the following:

![Data templating sample screenshot](./media/datatemplatingintro-fig2.png "DataTemplatingIntro_fig2")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox displaying a list of tasks.](./media/datatemplatingintro-fig2.png "DataTemplatingIntro_fig2")

However, that is limiting and inflexible. Also, if you are binding to XML data, you wouldn't be able to override `ToString`.

Expand All @@ -61,7 +61,7 @@ The WPF data templating model provides you with great flexibility to define the

Now our <xref:System.Windows.Controls.ListBox> looks like the following:

![Data templating sample screenshot](./media/datatemplatingintro-fig3.png "DataTemplatingIntro_fig3")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox displaying the tasks as TextBlock elements.](./media/datatemplatingintro-fig3.png "DataTemplatingIntro_fig3")

<a name="defining_datatemplate_as_a_resource"></a>
### Creating the DataTemplate as a Resource
Expand Down Expand Up @@ -98,15 +98,15 @@ The WPF data templating model provides you with great flexibility to define the

The following screenshot shows the <xref:System.Windows.Controls.ListBox> with this modified <xref:System.Windows.DataTemplate>:

![Data templating sample screenshot](./media/datatemplatingintro-fig4.png "DataTemplatingIntro_fig4")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox with the modified DataTemplate.](./media/datatemplatingintro-fig4.png "DataTemplatingIntro_fig4")

We can set <xref:System.Windows.Controls.Control.HorizontalContentAlignment%2A> to <xref:System.Windows.HorizontalAlignment.Stretch> on the <xref:System.Windows.Controls.ListBox> to make sure the width of the items takes up the entire space:

[!code-xaml[DataTemplatingIntro_snip#Stretch](~/samples/snippets/csharp/VS_Snippets_Wpf/DataTemplatingIntro_snip/CSharp/Window1.xaml#stretch)]

With the <xref:System.Windows.Controls.Control.HorizontalContentAlignment%2A> property set to <xref:System.Windows.HorizontalAlignment.Stretch>, the <xref:System.Windows.Controls.ListBox> now looks like this:

![Data templating sample screenshot](./media/datatemplatingintro-fig5.png "DataTemplatingIntro_fig5")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox stretched to fit the screen horizontally.](./media/datatemplatingintro-fig5.png "DataTemplatingIntro_fig5")

<a name="DataTrigger_to_Apply_Property_Values"></a>
### Use DataTriggers to Apply Property Values
Expand All @@ -120,7 +120,7 @@ The WPF data templating model provides you with great flexibility to define the

Our application now looks like the following. Home tasks appear with a yellow border and office tasks appear with an aqua border:

![Data templating sample screenshot](./media/datatemplatingintro-fig6.png "DataTemplatingIntro_fig6")
![Screenshot of the Introduction to Data Templating Sample window showing the My Task List ListBox with the home and office task borders highlighted in color.](./media/datatemplatingintro-fig6.png "DataTemplatingIntro_fig6")

In this example the <xref:System.Windows.DataTrigger> uses a <xref:System.Windows.Setter> to set a property value. The trigger classes also have the <xref:System.Windows.TriggerBase.EnterActions%2A> and <xref:System.Windows.TriggerBase.ExitActions%2A> properties that allow you to start a set of actions such as animations. In addition, there is also a <xref:System.Windows.MultiDataTrigger> class that allows you to apply changes based on multiple data-bound property values.

Expand Down Expand Up @@ -160,7 +160,7 @@ This example uses the [DataTemplate.Resources](xref:System.Windows.FrameworkTemp

With the template selector in place, the <xref:System.Windows.Controls.ListBox> now appears as follows:

![Data templating sample screenshot](./media/datatemplatingintro-fig7.png "DataTemplatingIntro_fig7")
![Screenshot of Introduction to Data Templating Sample window showing the My Task List ListBox with the Priority 1 tasks prominently displayed with a red border.](./media/datatemplatingintro-fig7.png "DataTemplatingIntro_fig7")

This concludes our discussion of this example. For the complete sample, see [Introduction to Data Templating Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Data%20Binding/DataTemplatingIntro).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Descendants (XElement dynamic property)
description: Learn how the XElement.Descendants property retrieves all the descendant elements of the current element that match the specified expanded name.
ms.date: 10/22/2019
ms.topic: reference
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Element (XElement dynamic property)
description: Learn how the XElement.Element property uses an indexer to retrieve the child element instance that corresponds to the specified expanded name.
ms.date: 10/22/2019
ms.topic: reference
apiname:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Elements (XElement dynamic property)
description: Learn how the XElement.Elements property uses an indexer to retrieve the child elements of the current element that match the specified expanded name.
ms.date: 10/22/2019
ms.topic: reference
apiname:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind the Properties of Two Controls"
description: Learn how to use the ElementName property to bind the property of one instantiated control to that of another.
ms.date: "03/30/2017"
helpviewer_keywords:
- "data binding [WPF], binding properties of two controls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind to an ADO.NET Data Source"
description: Learn how to bind a Windows Presentation Foundation (WPF) control to an ADO.NET Data Source with several provided code examples.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind to an Enumeration"
description: Learn how to bind to an enumeration by binding to the enumeration's GetValues method in Windows Presentation Foundation (WPF).
ms.date: "03/30/2017"
helpviewer_keywords:
- "binding data [WPF], enumeration"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind to the Results of a LINQ Query"
description: Learn how to run a LINQ query and then bind to the results in Windows Presentation Foundation (WPF).
ms.date: "03/30/2017"
helpviewer_keywords:
- "running a LINQ query [WPF], bind to results"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind to XDocument, XElement, or LINQ for XML Query Results"
description: Learn how to bind to XDocument, XElement, or LINQ for XML query results in Windows Presentation Foundation (WPF).
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Bind to XML Data Using an XMLDataProvider and XPath Queries"
description: Learn how to bind to XML data using an XMLDataProvider and XPath queries in Windows Presentation Foundation (WPF).
ms.date: "03/30/2017"
helpviewer_keywords:
- "XmlDataProvider [WPF], binding to XML data"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Clear Bindings"
description: Learn how to use ClearBinding to remove a binding from an individual property on an object in Windows Presentation Foundation (WPF).
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Convert Bound Data"
description: Learn how to use the IValueConverter interface and the Convert and ConvertBack methods to convert bound data.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Filter Data in a View"
description: Learn how to create a filter and define a method that provides filtering logic to filter data in a view.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Find DataTemplate-Generated Elements"
description: Learn how to find elements that are generated by a DataTemplate with several provided code examples.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Get the Binding Object from a Bound Target Property"
description: Learn how to retrieve the binding object from a data-bound target property with several provided code examples.
ms.date: "03/30/2017"
helpviewer_keywords:
- "data binding [WPF], getting binding objects from bound target properties"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Get the Default View of a Data Collection"
description: Learn how to use the DataContext of a data object to retrieve the default view of a data collection.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Implement a CompositeCollection"
description: Learn how to use the CompositeCollection class to display multiple collections and items as one list.
ms.date: "03/30/2017"
helpviewer_keywords:
- "data binding [WPF], CompositeCollection class"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Implement PriorityBinding"
description: Learn how to use PriorityBinding to define a list of bindings ordered from highest to lowest priority.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Implement Validation Logic on Custom Objects"
description: Learn how to implement validation logic on a custom object before binding to it in Windows Presentation Foundation (WPF).
ms.date: "08/02/2018"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Navigate Through the Objects in a Data CollectionView"
description: Learn how to use the CollectionView class to retrieve the current object as well as navigate through the objects in a data collection.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Produce a Value Based on a List of Bound Items"
description: Learn how to use MultiBinding to apply logic and produce a value based on a list of bound items with given inputs.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Set Up Notification of Binding Updates"
description: Learn how to use the INotifyPropertyChanged interface to set up notification when source or target binding properties have been updated.
ms.date: "03/30/2017"
helpviewer_keywords:
- "notifications [WPF], binding updates"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Sort Data in a View"
description: Learn about various techniques to sort data in a view including related tutorials and several provided code examples.
ms.date: "03/30/2017"
dev_langs:
- "csharp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "How to: Specify the Direction of the Binding"
description: Learn how to use the Binding.Mode property to specify whether the binding updates only the target property, the source property or both.
ms.date: "03/30/2017"
helpviewer_keywords:
- "direction of binding [WPF]"
Expand Down