Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-use-xml-namespaces-in-data-binding.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

1.7 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Use XML Namespaces in Data Binding 03/30/2017
XML [WPF], namespaces
data binding [WPF], XML namespaces
namespaces [WPF], XML
a47c832f-dc84-48f2-96d5-cde18fc4284b

How to: Use XML Namespaces in Data Binding

Example

This example shows how to handle namespaces specified in your XML binding source.

If your XML data has the following XML namespace definition:

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">

You can use the xref:System.Windows.Data.XmlNamespaceMapping element to map the namespace to a xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A, as in the following example. You can then use the xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A to refer to the XML namespace. The xref:System.Windows.Controls.ListBox in this example displays the title and dc:date of each item.

[!code-xamlXmlnsBindSnippet#XmlNamespaceMapping]

Note that the xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A you specify does not have to match the one used in the XML source; if the prefix changes in the XML source your mapping still works.

In this particular example, the XML data comes from a web service, but the xref:System.Windows.Data.XmlNamespaceMapping element also works with inline XML or XML data in an embedded file.

See also