Sladescross's Blog

Blogging about Sharepoint related stuff

WPF XML Binding and Namespaces September 30, 2011

Filed under: Local-Name,WPF,XMLNameSpaceManager — sladescross @ 11:37 am

I suppose after looking at the code, you should be able to understand why it works after specify the Binding.XmlNamespaceManager attached property for TextBlock.

ListBox is data bound to a data provider which has xml namespace mapping information, but the binding on the TextBlock doesn’t have this information, that’s why it fails.

Actually, when doing master detail data binding, it’s more appropriate to do something like the following:

<Page xmlns=”;
        <XmlNamespaceMappingCollection x:Key=”namespaceMappings”>
            <XmlNamespaceMapping Uri=”; Prefix=”p”/>
        <XmlDataProvider x:Key=”dataProvider”
                         XmlNamespaceManager=”{StaticResource namespaceMappings}”
                <p:players xmlns:p=””&gt;
                        <p:fullName>Sebastian Batistuta</p:fullName>
                        <p:fullName>Andriey Shevchenko</p:fullName>
                        <p:fullName>Paviel Nedved</p:fullName>
                        <p:fullName>David Beckham</p:fullName>
    <StackPanel DataContext=”{Binding Source={StaticResource dataProvider}}”>
            Text=”{Binding XPath=p:fullName}”
        <ListBox ItemsSource=”{Binding}”

<TextBox Name=”nameText”> 
       <Binding XPath=”*[local-name()='Name']” /> 

About these ads

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 63 other followers