Reputation: 301
I want to create my own XML data provider derived from DataSourceProvider (similar XmlDataProvider).
(i don't want use XmlDataProvider because i want return alternative data if XPath query is failed)
But i can't understand how to access XPath property which set via Binding.XPath.
For example, i have class:
public class MyXmlDataProvider : DataSourceProvider
{
private string _xPath;
public string XPath
{
// The following code i spied from XmlDataProvider implementation using .Net Reflector
get
{
return this._xPath;
}
set // WHY binding do not call this setter? ((
{
if (this._xPath != value)
{
this._xPath = value;
if (!base.IsRefreshDeferred)
{
base.Refresh();
}
}
}
}
private string _result;
protected override void BeginQuery()
{
// .... getting result using XPath
base.OnQueryFinished(_result);
}
}
XAML binding example (mydata - instance of MyXmlDataProvider class):
<TextBlock Text="{Binding Source={StaticResource mydata}, XPath=/main/version}" />
Question is: How can i get Binding.XPath value in MyXmlDataProvider class?
Upvotes: 1
Views: 1227
Reputation: 301
I found source code of XmlDataProvider here:
But i solved my task by implementing a class with indexer (not a descendent of DataSourceProvider):
public string this[string xpath]
{
// Here i do XPath-query and handle its result
...
}
XPath-query i set in the binding as follows:
<TextBlock Text="{Binding Source={StaticResource mydata}, Path=[/main/version]}" />
Upvotes: 2