获取表单属性`不能显式调用运算符或访问器`
问题描述:
我正在为 wp7 制作一个小应用程序,当我尝试从参考资料中获取时出现错误.
I'm makeing a small app for wp7, and I'm haveing an error when I try to get from a reference.
代码如下:
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
当我尝试从属性添加或设置时遇到了同样的错误,我在网上查看,但找不到解决方案.
I'm having the same error when I try to add or set from a property, and I looked on the web, but I couldn't find the solution.
答
您正在使用基础方法名称.而不是这样:
You're using the underlying method names. Instead of this:
ShellTile current = enumerator.get_Current();
你想要:
ShellTile current = enumerator.Current;
等等.但是,我也建议使用 foreach
循环而不是显式调用 GetEnumerator
等:
etc. However, I would also suggest using a foreach
loop instead of explicitly calling GetEnumerator
etc:
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:
Also note that .NET naming conventions would suggest that findById
etc should be PascalCased:
FindById
GetTileId
CreateShellTile