c# - 乔什·史密斯文章的解释

标签 c# mvvm icommand

你们中的许多人都熟悉Josh Smith。他在解释事物方面做得很出色,但是他在文章中做了一个特别的陈述:

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

让我感到困惑...

关于ICommandRelayCommand类,他提到:

One possible implementation pattern is to create a private nested class within the ViewModel class, so that the command has access to private members of its containing ViewModel and does not pollute the namespace.



也许因为我是新手,所以我很难想象他在说什么。有人可以给我发送一些伪代码来解释这个吗?我认为看到代码将帮助我掌握概念。

最佳答案

class Foo
{
   private static int f;

   private class Bar  // nested class
   {
       void B() 
       { 
          int b = f;  // access to private member of containing class
       }
   }
}

但请注意,本文仍在继续使用中。

关于c# - 乔什·史密斯文章的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9673872/

相关文章:

c# - 将自定义创建的位图绘制到屏幕

c# - 如何使用 XPathDocument 和 C# 获取节点数?

c# - 系统异常 : 'Cannot create a table without columns, 是否具有公共(public)属性?

user-interface - Xamarin表单框架未随内容扩展

c# - WPF 绑定(bind) : Set Listbox Item text color based on property

c# - 将模型绑定(bind)到 View ,但按钮单击工作

c# - MVC 3 图像未加载

asp.net-mvc - ASP.NET MVC 4 Web API & Knockout.js

c# - CommandParameter 上的 DataContext 与 Command 本身上的 DataContext 不同

c# - 如何使用 MVVM 通过命令正确实现 TextChanged 事件