J'ai XML similaire à laComment me lier à XmlDataProvider dont la source possède un espace de noms par défaut (xmlns)?
<?xml version="1.0" encoding="utf-8"?>
<foo name="FooBar" xmlns="http://mydomain/myapp/ver/myschema.xsd">
<bars v="test">
<bar bat="one"/>
<bar bat="two"/>
<bar bat="three"/>
</bars>
</foo>
suivant Comment mapper ceci dans WPF, cela fonctionne si je ne mets pas l'espace de noms par défaut, mais quand je xmlns
tournerai ma liaison ne correspond pas à quoi que ce soit. J'ai essayé les déclarations suivantes mais j'ai du mal à trouver comment mapper la liste déroulante comme indiqué ci-dessous.
<Window.Resources>
<!-- works if xmlns is not set -->
<XmlDataProvider x:Key="mySource1"
XPath="/foo">
<!-- also tried -->
<XmlDataProvider x:Key="mySource2"
XPath="//*[local-name()='foo']">
<!-- also tried -->
<XmlDataProvider x:Key="mySource3"
XPath="/foo">
<XmlDataProvider.XmlNamespaceManager>
<XmlNamespaceMappingCollection>
<XmlNamespaceMapping
Uri="http://mydomain/myapp/ver/myschema.xsd"
Prefix=""/>
</XmlNamespaceMappingCollection>
</XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
</Window.Resources>
<StackPanel DataContext="{StaticResource mySource1}">
<Label Content="{Binding [email protected]}"/>
<Label DataContext="{Binding XPath=bars}"
Content="{Binding [email protected]}"/>
</StackPanel>
Je suis attribuer la propriété XmlDataProvider.Source
par le code suivant.
XmlDataProvider xdp = FindResource("mySource1") as XmlDataProvider;
// ... setup dialog and confirm resource.
using (Stream s = dlg.OpenFile()) {
XmlDocument doc = new XmlDocument();
doc.Load(s);
xdp.Document = doc;
}
Toute aide résolvant ceci serait très appréciée, merci.
MISE À JOUR
De suggestion Andrews, je suis venu avec ce qui suit:
<Window.Resources>
<XmlDataProvider x:Key="mySource"
XPath="/fb:foo">
<XmlDataProvider.XmlNamespaceManager>
<XmlNamespaceMappingCollection>
<XmlNamespaceMapping
Uri="http://mydomain/myapp/ver/myschema.xsd"
Prefix="fb"/>
</XmlNamespaceMappingCollection>
</XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
</Window.Resources>
<StackPanel DataContext="{StaticResource mySource}">
<Label Content="{Binding [email protected]}"/>
<ComboBox ItemsSource="{Binding XPath=fb:bars/fb:bar}"
IsSynchronizedWithCurrentItem="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding [email protected]}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
J'ai trouvé le problème provient du fait que mon problème du monde réel est obligatoire pour 'la SelectedItem' d'un combobox qui ne semble pas fonctionner avec l'espace de noms, a ouvert le suivi sur la question http: // stackoverflow.com/questions/1909416/having-trouble-getting-parent-child-combobox-to-bind-against-xml-datasource-prob –