문제

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.

도움이 되었습니까?

해결책

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");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top