我刚刚使用网格应用程序模板创建了一个新的Windows 8应用程序,只是我想在我的xaml代码中添加一个新的文本块,并在组中的每个项目上绑定一些数据,如何编辑数据来源并添加新项目?我的代码如下:
<XAML>
<TextBlock x:Name="Contact" Text="{Binding Contact}" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Height="471" Margin="1022,101,0,0" RenderTransformOrigin="0.5,0.5" Width="282" FontSize="15"/>
<C# - SampleDataSource>
public class SampleDataItem
{
public SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, String contact)
{
this.UniqueId = uniqueId;
this.Title = title;
this.Subtitle = subtitle;
this.Description = description;
this.ImagePath = imagePath;
this.Content = content;
this.Contact = contact;
}
public string UniqueId { get; private set; }
public string Title { get; private set; }
public string Subtitle { get; private set; }
public string Description { get; private set; }
public string ImagePath { get; private set; }
public string Content { get; private set; }
public string Contact { get; private set; }
{
JsonObject itemObject = itemValue.GetObject();
group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
itemObject["Title"].GetString(),
itemObject["Subtitle"].GetString(),
itemObject["ImagePath"].GetString(),
itemObject["Description"].GetString(),
itemObject["Contact"].GetString(),
itemObject["Content"].GetString()));
}
注意:我已经跳过了与此处无关的任何C#代码..当我运行代码时,我得到一个异常,说用户代码未处理KeyNotFoundException并通过绘制的行引用这行代码: var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
答案 0 :(得分:0)
在哪里初始化/设置itemValue
的valze?您确定此项目包含您要访问的所有密钥吗?