我正在尝试在文本块附近插入图像。我有一系列球队,我想在他们的名字附近添加这支球队的盾牌。所以在WPF中我做了这个结构:
<DataGrid x:FieldModifier="public" x:Name="League_DataGrid" Grid.ColumnSpan="4" HorizontalAlignment="Left" Margin="10,368,0,0" VerticalAlignment="Top" Height="181" Width="676" AutoGenerateColumns="False">
<DataGrid.Columns >
<DataGridTextColumn Binding="{Binding Path = 'position'}" Header="Posizione" CanUserResize="False" />
<DataGridTemplateColumn Header="Squadra">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<TextBox Text="{Binding Path='name'}"/>
</Grid>
<Grid>
<Image Source="{Binding Path='logo'}"/>
</Grid>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Path = 'points'}" Header="Punti" CanUserResize="true" MinWidth="150" MaxWidth="200" />
<DataGridTextColumn Binding="{Binding Path = 'playedGames'}" Header="Partite Giocate" CanUserResize="False" />
<DataGridTextColumn Binding="{Binding Path = 'goals'}" Header="Goal" CanUserResize="False" />
<DataGridTextColumn Binding="{Binding Path = 'goalsAgainst'}" Header="Goal Subiti" CanUserResize="False" />
<DataGridTextColumn Binding="{Binding Path = 'goalsDifference'}" Header="Differenza Reti" CanUserResize="False" />
</DataGrid.Columns>
</DataGrid>
因此,在c#代码中,我创建了一个填充DataGrid的函数。
int i=0;
foreach (var classifica in leagueTable_Object.standing)
{
MainWindow.AppWindow.League_DataGrid.Items.Add(new LeagueTable.Classifica
{
position = classifica.position,
name = classifica.teamName,
logo = SvgReader.Load(new MemoryStream(new System.Net.WebClient().DownloadData(Teams.team_struct[i].logo))),
playedGames = classifica.playedGames,
goals = classifica.goals,
goalsAgainst = classifica.goalsAgainst,
goalsDifference = classifica.goalDifference
});
i++;
}
问题是当我执行这段代码时,我得到了这个例外:
XmlException was not managed.
我做错了什么? 堆栈跟踪:
Eccezione generata: 'System.Xml.XmlException' in System.Xml.dll
in System.Xml.XmlTextReaderImpl.Throw(Exception e)
in System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
in System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
in System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
in System.Xml.XmlTextReaderImpl.ReadData()
in System.Xml.XmlTextReaderImpl.SwitchEncoding(Encoding newEncoding)
in System.Xml.XmlTextReaderImpl.SwitchEncodingToUTF8()
in System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
in System.Xml.XmlTextReaderImpl.Read()
in System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
in System.Xml.Linq.XDocument.Load(XmlReader reader)
in Svg2Xaml.SvgReader.Load(XmlReader reader, SvgReaderOptions options)
in Svg2Xaml.SvgReader.Load(Stream stream, SvgReaderOptions options)
in Svg2Xaml.SvgReader.Load(Stream stream)
in Test.LeagueTable.load_League_Table() in C:\Users\Anto\documents\visual studio 2015\Projects\Test\Test\LeagueTable.cs:riga 117