Question

I'm unable to bind a XamDataGrid to an XmlDataProvider property in my MVVM styled project.

I'm getting an XML string from a WebService call, creating an XmlDataProvider and then trying to bind it to the XamDataGrid. The XmlDataProvider is getting initialized properly. It's just the binding part that's not going right.

View.xaml

<igDP:XamDataGrid DataSource="{Binding Source=provider, XPath=Row, Mode=OneWay}" />


ViewModel.cs

public XmlDataProvider provider { get; private set; }

private void method()
{
            string xmlString = webservice.runQuery();

            // prepare xml
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlString);

            provider = new XmlDataProvider();

            if (provider != null)
            {
                provider.Document = doc;
                provider.XPath = "/Results";
            }
}


Sample xml string

<Results>
    <Row>
        <! -- my data -->
    </Row>

    <Row>
        <! -- my data -->
    </Row>
</Results>

I was able to do this without much difficulty in the code-behind way by following the sample Infragistics code. But, it's the MVVM way I'm having difficulty with.

This solution doesn't seem to work for XamDataGrid.

Was it helpful?

Solution

This worked:

<igDP:XamDataGrid DataContext="{Binding provider}" DataSource="{Binding XPath=Row, Mode=OneWay}" />

Also, I was originally missing the following:

private set
{
    _provider = value;
    OnPropertyChanged("provider");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top