我当前正在使用以下代码在窗口中加载XmlDataProvider:
var current = new Date();
var day = current.getDay();
var currentTime = (currentTime) = (current.getHours() * 60) + current.getMinutes();
var remainTime = 0;
var closeTime = (openTime[day].close *60);
var openTime = (openTime[day].open *60);
和一个HierarchicalDataTemplate:
<XmlDataProvider x:Key="xmldata" Source="C:\test-file.xml" XPath="/root" />
然后我将一个Grid / TreeView绑定到该提供程序
<HierarchicalDataTemplate DataType="MenuItem" ItemsSource="{Binding XPath=./*}">
<StackPanel>
<Image Source="{Binding XPath=@icon}" />
<TextBlock Text="{Binding XPath=@name}" />
</StackPanel>
</HierarchicalDataTemplate>
我的最终目标是从流中加载XML文件并对其进行解码; 如何通过C#以编程方式设置XmlDataProvider以及关联的x:Key等。
是否需要设置XmlDataProvider,然后以编程方式设置Grid的DataContext?