Hi,
on application startup a xamDataGrid is bound to static resource:
<Grid.Resources> <XmlDataProvider x:Key="Data" XPath="/Ntn"> <x:XData> <Ntn xmlns=""> <Note GridHeaderSA="SA" GridHeaderKA="KA" GridHeaderEx="Ex" GridHeaderM="M" /> </Ntn> </x:XData> </XmlDataProvider></Grid.Resources>
This xmlDataProvider is bound as datasource:
<igDP:XamDataGrid DataSource="{Binding Source={StaticResource Data},XPath=Ntn}" />
At runtime data is gathered and loaded into an ObservableCollection and this collection is bound to the xamDataGrid:
Me.gridNtn.DataSource = myDataCollection
Now would like to create the following behaviour:
If data is loaded correctly, i would like to view this in the grid. If loading fails, the grid should "fallback" to the static resource. But how to do this in Code?
In short terms: is it possible to bind a xamDataGrid to static resource in code?
thanks in advance
Stephan
Hello Stephan,
Thank you for your post. I have been looking into it and I suggest you use the following code in order to bind the XamDataGrid to the static resource:
XmlDataProvider data = grid1.Resources["Data"] as XmlDataProvider; Binding b = new Binding(); b.Source = data; b.XPath = "Note"; xamDataGrid1.SetBinding(XamDataGrid.DataSourceProperty,b);
Where grid1 is the name of the Grid where you define the XmlDataProvider and the xamDataGrid1 is the name of the XamDataGrid.Please let me know if this helps you or you need further clarifications on this matter.
Looking forward for your reply.
Hi Stefan,
thank you for your answer. This solves my problem.
Thanks
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.