我想創建自己的DataSourceProvider(類似XmlDataProvider)派生的XML數據提供程序。自定義XML數據提供程序(WPF)
(我不想使用XmlDataProvider因爲我想,如果XPath查詢失敗返回替代數據)
,但我可以不知道如何訪問它通過Binding.XPath設置XPath屬性。
例如,我有類:
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結合的例子(MYDATA - MyXmlDataProvider類的實例):
<TextBlock Text="{Binding Source={StaticResource mydata}, XPath=/main/version}" />
的問題是:我怎樣才能在MyXmlDataProvider Binding.XPath值類?