Binding to a ViewModel property
Please bear with me, I know very little about WPF so I might be way off target with this...
I currently have a static resource defined as follows:
<XmlDataProvider
x:Key="staticData"
Source="http://someurl/desktopservices/some.xml"
XPath="/menu"/>
This is bound to a Menu control as follows:
<Menu
ItemsSource="{Binding Source={StaticResource staticData}}"
x:Name="MyMenu" />
All is good.
Now I define a view model and create the XmlDataProvider as a propery of the vm:
public class ViewModel : INotifyPropertyChanged
{
private readonly XmlDataProvider dataProvider;
public ViewModel()
{
var document = new XmlDocument();
document.Loa开发者_运维百科d("http://someurl/desktopservices/some.xml");
dataProvider = new XmlDataProvider
{
Document = document,
XPath = @"/menu"
};
}
public XmlDataProvider DataProvider
{
get
{
return dataProvider;
}
}
//....
}
The ViewModel is then defined in XAML as another StaticResource:
<local:ViewModel x:Key="vm"/>
How do I change my binding to the DataProvider
property of the view model? I would expect:
<Menu
ItemsSource="{Binding DataProvider, Source={StaticResource vm}}"
x:Name="MyMenu" />
(I've tried other combos... this is the one that doesn't error... however nothing gets bound)
精彩评论