0

我正在为 wp7 制作一个小应用程序,当我尝试从参考中获取时出现错误。

类似这样的代码:

   private void refreshExistingShellTile()
    {
        using (IEnumerator<ShellTile> enumerator = ShellTile.get_ActiveTiles().GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                ShellTile current = enumerator.get_Current();
                if (null != current.get_NavigationUri() && !current.get_NavigationUri().ToString().Equals("/"))
                {
                    Black_n_Gold.Entities.Tile tile = App.CurrentApp.tileService.findById(App.CurrentApp.tileService.getTileId(current.get_NavigationUri().ToString()));
                    if (tile != null && tile.id == this.customizedTile.id)
                    {
                        current.Delete();
                        this.createShellTile(this.customizedTile);
                    }
                }
            }
        }
    } 

我有这个错误:

'Microsoft.Phone.Shell.ShellTile.ActiveTiles.get': cannot explicitly call operator or accessor
'Microsoft.Phone.Shell.ShellTile.NavigationUri.get': cannot explicitly call operator or accessor
'System.Collections.Generic.IEnumerator<Microsoft.Phone.Shell.ShellTile>.Current.get': cannot explicitly call operator or accessor

当我尝试从属性添加或设置时,我遇到了同样的错误,我在网上查看,但找不到解决方案。

4

1 回答 1

2

您正在使用底层方法名称。而不是这个:

ShellTile current = enumerator.get_Current();

你要:

ShellTile current = enumerator.Current;

等等。但是,我建议使用foreach循环而不是显式调用GetEnumerator等:

private void refreshExistingShellTile()
{
    foreach (ShellTile current in ShellTile.ActiveTiles)
    {
        Uri uri = current.NavigationUri;
        if (uri != null && uri.ToString() != "/")
        {
            Black_n_Gold.Entities.Tile tile = App.CurrentApp.tileService
                .findById(App.CurrentApp.tileService.getTileId(uri.ToString());
            if (tile != null && tile.id == customizedTile.id)
            {
                current.Delete();
                createShellTile(customizedTile);
            }
        }
    }
}

另请注意,.NET 命名约定建议findByIdetc 应为 PascalCased:

  • FindById
  • GetTileId
  • CreateShellTile
于 2013-01-06T19:41:32.837 回答