我想在我的datagrid中显示一个外部xml文件。 在Designer中,它会向我显示正确的数据,但是如果我运行我的应用程序,该数据将不再显示在我的datagrid中。我错过了什么吗?
<Window x:Class="WpfApp1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Window.Resources>
<XmlDataProvider x:Key="Data" Source="Events.xml" XPath="Events"/>
</Window.Resources>
<Grid>
<DataGrid AutoGenerateColumns="False" DataContext="{StaticResource Data}" ItemsSource="{Binding XPath=Entrys}">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Visibility="Hidden" Binding="{Binding XPath=ID}"/>
<DataGridTextColumn Header="Time" Binding="{Binding XPath=Time}"/>
<DataGridTextColumn Header="Type" Binding="{Binding XPath=Type}"/>
<DataGridTextColumn Header="Name" Binding="{Binding XPath=Name}"/>
<DataGridTextColumn Header="Msg" Binding="{Binding XPath=Msg}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
我的Xml文件:
<Events>
<Entrys>
<ID>0</ID>
<Time>23:44</Time>
<Type>Follow</Type>
<Name>xPowerbot</Name>
<Msg>New Follower</Msg>
</Entrys>
</Events>