3

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 });
4

2 に答える 2

3

WP8 で実行しているときに WP7.1 アプリで新しいタイルを作成するための作業ラッパーを含むライブラリ Mangopollo を試しましたか?
http://mangopollo.codeplex.com/

于 2012-11-30T07:00:07.633 に答える
0

コード全体でリフレクションが有効になっていることを確認する必要があります。

アイコン タイルは Windows Phone 8 でのみ使用できるため、バージョンを確認した場合にのみコードを Windows Phone 7.1 プロジェクトに配置できます。

private static Version TargetedVersion = new Version(8, 0);
    public static bool IsTargetedVersion {get{
               return Environment.OSVersion.Version >=    TargetedVersion;}}

bool IsTargetedVersion が true かどうかを確認します。基本的、

if(IsTargetedVersion){
      //iconic tile code
}

したがって、互換性のある機能 (つまり、wp8) を備えた Windows Phone でアプリを実行した場合にのみ、機能します。

于 2012-11-30T02:23:02.423 に答える