MSDNのドキュメントを使用して、既存の Windows Phone OS 7.1 アプリケーションで新しい Windows Phone タイル機能をサポートしようとしています。ただし、NullReferenceExceptions と AmbiguousMatchExceptions が発生し続けるため、リフレクションを介して IconicTile を作成できないようです。私が使用しているコードは次のとおりです。
public static void CreateIconicTile(Uri tileId, string title, int count, string wideContent1, string wideContent2, string wideContent3, Uri smallIconImage, Uri iconImage, Color backgroundColor)
{
// Get the new IconicTileData type.
Type iconicTileDataType = Type.GetType("Microsoft.Phone.Shell.IconicTileData, Microsoft.Phone");
// Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates.
Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
// Get the constructor for the new IconicTileData class and assign it to our variable to hold the Tile properties.
StandardTileData CreateTileData = new StandardTileData();
// Set the properties.
SetProperty(CreateTileData, "Count", count);
SetProperty(CreateTileData, "WideContent1", wideContent1);
SetProperty(CreateTileData, "WideContent2", wideContent2);
SetProperty(CreateTileData, "WideContent3", wideContent3);
SetProperty(CreateTileData, "SmallIconImage", smallIconImage);
SetProperty(CreateTileData, "IconImage", iconImage);
SetProperty(CreateTileData, "BackgroundColor", backgroundColor);
// Invoke the new version of ShellTile.Create.
shellTileType.GetMethod("Create").Invoke(null, new Object[] { tileId, CreateTileData });
}
また、Windows Phone OS 7.1 の方法 ( ) を使用してタイルを作成し、MSDN のドキュメントで説明されているように、リフレクションを介してメソッドをShellTile.Create(...)
呼び出してみました。UpdateIconicTile
しかし、それもうまくいきませんでした。
どんな助けでも大歓迎です。ありがとう!
編集: 明確にするために、プラットフォームのバージョンをチェックして、このコードが Windows Phone 8 デバイスでのみ実行されるようにし、必要なコードをマニフェストに追加しました。
解決済み: 以下の Martin Suchan による回答のおかげで、この問題を解決することができました。Invoke(...)
問題は、いくつかのプロパティが欠落しているという私の呼び出しにありました。実際にタイルを作成するために使用している新しい行は次のとおりです。
shellTileType.GetMethod("Create", new Type[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }).Invoke(null, new Object[] { tileId, CreateTileData, true });