我正在尝试从显示我所有的 Xbox Live 好友信息的 XML 文档中获取信息。我现在想要做的是在动态创建的图像控件中显示头像,但我不确定如何实际让该图像显示在我的应用程序网格上。
到目前为止,我已经尝试过使用玩家标签创建一个动态控件并将我的自定义文本添加到其中。这是到目前为止的代码:
string gamertag, avatarURL;
foreach (XElement elm in doc.Descendants().Elements("Friends"))
{
gamertag = elm.Element("Gamertag").Value;
avatarURL = elm.Element("AvatarLarge").Value;
Image friendimage = new Image();
friendimage.Name = gamertag.ToString() + "ImageControl";
BitmapImage AccountPicbitmap = new BitmapImage();
AccountPicbitmap.UriSource = new Uri(avatarURL);
friendimage.Source = AccountPicbitmap;
//Some code to display this control with the avatar image using the URL retrieved, I want to play these tiles side by side
}
关于我如何做到这一点的任何建议?提前致谢!
更新:我已将此控件添加到我的 XAML 中,但现在我遇到了一些奇怪的异常: System.Runtime.Remoting.RemotingException [7756] 设计器进程意外终止!
<ItemsControl HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="1249" Margin="55,484,0,0" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding avatarURL}" Name="{Binding GamerTag}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
现在,当我调试应用程序时,它会进入无限循环并在初始化时引发异常
public MainPage()
{
this.InitializeComponent();
}