C# 更新磁贴数据时模板类型不匹配
我正在尝试为我的windows phone应用程序创建和更新互动程序。但是,当我尝试实现下面的代码时(这对msdn示例很有用),它抛出“在Microsoft.Phone.ni.dll中发生了“System.ArgumentException”类型的异常,但未在用户代码中处理 其他信息:模板类型不匹配。只能使用创建互动程序时使用的模板更新互动程序。“C# 更新磁贴数据时模板类型不匹配,c#,windows-phone-8.1,live-tile,C#,Windows Phone 8.1,Live Tile,我正在尝试为我的windows phone应用程序创建和更新互动程序。但是,当我尝试实现下面的代码时(这对msdn示例很有用),它抛出“在Microsoft.Phone.ni.dll中发生了“System.ArgumentException”类型的异常,但未在用户代码中处理 其他信息:模板类型不匹配。只能使用创建互动程序时使用的模板更新互动程序。“ 异常由“TileToFind.Update(NewTileData);”行引发。我在等你的建议。谢谢。在Windows Phone 8中,您可以查看
异常由“TileToFind.Update(NewTileData);”行引发。我在等你的建议。谢谢。在Windows Phone 8中,您可以查看项目中的
WMAppManifest.xml
。平铺模板可以是TemplateFlip、TemplateCycle或TemplateIconic。他们的瓷砖数据如下:
FlipTileData(TemplateFlip)、CycleTileData(TemplateCycle)和IconicTileData(TemplateIconic)。
根据WMAppManifest.xml中的平铺模板类型选择right TileData。您的应用程序目标是WP8.1、WP8还是Wp7?据我所知,Windows Phone 8.1无法在Microsoft.Phone.Shell命名空间中使用ShellTile。如果你的应用程序是目标WP8,你应该用同样的方法创建和更新磁贴。例如,如果使用FlipTileData创建互动程序,则应使用FlipTileData对其进行更新。然后,它应为WP8。当我安装WP8.1 SDK时,VisualStudio改变了我的想法。那么,我如何才能知道存在哪种类型的磁贴进行更新?由于ShellTile.ActiveTiles返回ShellTile,因此它总是对所有平铺类型抛出异常。我如何实现它?顺便说一下,谢谢。请读我的答案。我会试试的,谢谢。如果可以的话,我会把它标记为答案。我错了!我将它改为TemplateIconsignal,但当它抛出异常时,我认为它是关于ShellTile和FlipTileData的,但事实并非如此。再次感谢你。我能问个问题吗?如何将我的项目更改为WP8.1,我需要做什么?再次感谢你,不客气。若您想以WP8.1为目标,只需右键单击project,您就会找到它。
int newCount = 0;
// Application Tile is always the first Tile, even if it is not pinned to Start.
ShellTile TileToFind = ShellTile.ActiveTiles.First();
// Application should always be found
if (TileToFind != null)
{
// if Count was not entered, then assume a value of 0
if (textBoxCount.Text == "")
{
// A value of '0' means do not display the Count.
newCount = 0;
}
// otherwise get the numerical value for Count
else
{
newCount = int.Parse(textBoxCount.Text);
}
// set the properties to update for the Application Tile
// Empty strings for the text values and URIs will result in the property being cleared.
StandardTileData NewTileData = new StandardTileData
{
Title = textBoxTitle.Text,
BackgroundImage = new Uri(textBoxBackgroundImage.Text, UriKind.Relative),
Count = newCount,
BackTitle = textBoxBackTitle.Text,
BackBackgroundImage = new Uri(textBoxBackBackgroundImage.Text, UriKind.Relative),
BackContent = textBoxBackContent.Text
};
// Update the Application Tile
TileToFind.Update(NewTileData);
}