我正在为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
当我尝试从属性添加或设置时,我遇到了同样的错误,我在网上查看,但我找不到解决方案。
答案 0 :(得分: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命名约定会建议findById
等应该是PascalCased:
FindById
GetTileId
CreateShellTile