先谢过各位高手和热心人。以下是步骤
1在资源中用x:Data写入静态Xml提供给XmlDataProvider,
2然后写入CollectionViewSource资源,其Source绑定到上面的XmlDataProvider
3通过CollectionViewSource资源提供数据给ListView,并填写View的GridView
现象,设计时数据正常显示,运行时结果无法显示。
环境,VisualStudio2010
代码
资源部分
<XmlDataProvider x:Key="TestDataProvider" XPath="Customers/*">
<x:XData>
<Customers>
<Customer DisplayName="Customer1" Email="customer1@hotmail.com" IsCompany="True" TotalSales="300200"></Customer>
<Customer DisplayName="Customer2" Email="customer1@hotmail.com" IsCompany="True" TotalSales="600200"></Customer>
<Customer DisplayName="Customer3" Email="customer1@hotmail.com" IsCompany="False" TotalSales="3000"></Customer>
<Customer DisplayName="Customer4" Email="customer1@hotmail.com" IsCompany="False" TotalSales="4000"></Customer>
<Customer DisplayName="Customer5" Email="customer1@hotmail.com" IsCompany="False" TotalSales="5000"></Customer>
</Customers>
</x:XData>
</XmlDataProvider>
<CollectionViewSource x:Key="TestCollectionViewSourceCustomers2"
Source="{Binding Source={StaticResource TestDataProvider}}">
</CollectionViewSource>
窗体部分
<DockPanel>
<ListView DockPanel.Dock="Top"
ItemsSource="{Binding Source={StaticResource TestCollectionViewSourceCustomers2}}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding
XPath=@DisplayName}">
</GridViewColumn>
<GridViewColumn Header="Email" DisplayMemberBinding="{Binding
XPath=@Email}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
谢谢!!