[proofplan]
We use the definition that a self-adjoint operator $T$ is affiliated with $M$ when every unitary operator in $M'$ commutes with $T$ in the domain-preserving sense. In one direction, affiliation implies commutation with the bounded [Borel functional calculus](/theorems/2696) of $T$, hence with the spectral projections $E_T(B)$; the bicommutant theorem then puts these projections in $M$. Conversely, if all spectral projections lie in $M$, then every unitary in $M'$ commutes with the spectral measure, so it preserves the spectral-[integral domain](/page/Integral%20Domain) of $T$ and commutes with the spectral integral defining $T$.
[/proofplan]
custom_env
admin
[step:Fix the affiliation convention and the spectral-integral domain]
We write $M' := \{a \in \mathcal{L}(H) : ax = xa \text{ for all } x \in M\}$ for the commutant of $M$. The self-adjoint operator $T$ is affiliated with $M$, written $T\eta M$, if for every unitary $u\in M'$ one has $uT\subseteq Tu$; equivalently, $u(\operatorname{Dom}(T))\subseteq \operatorname{Dom}(T)$ and
\begin{align*}
T(u\xi)=u(T\xi)
\end{align*}
for every $\xi\in\operatorname{Dom}(T)$. Since $u^{-1}\in M'$ is also unitary, this condition implies $u(\operatorname{Dom}(T))=\operatorname{Dom}(T)$.
For $\xi\in H$, define the finite positive Borel measure $\mu_\xi$ on $\mathbb{R}$ by
\begin{align*}
\mu_\xi(B)=(E_T(B)\xi,\xi)_H,\qquad B\in\mathcal{B}(\mathbb{R}).
\end{align*}
By the [spectral theorem for self-adjoint operators](/theorems/6911), the domain of $T$ is
\begin{align*}
\operatorname{Dom}(T)=\left\{\xi\in H:\int_{\mathbb{R}}\lambda^2\,d\mu_\xi(\lambda)<\infty\right\}.
\end{align*}
Moreover, if $f:\mathbb{R}\to\mathbb{C}$ is a bounded Borel function, the bounded Borel functional calculus gives an operator
\begin{align*}
f(T)=\int_{\mathbb{R}}f(\lambda)\,dE_T(\lambda)\in\mathcal{L}(H).
\end{align*}
[/step]
custom_env
admin
[step:Derive membership of the spectral projections from affiliation]Assume $T\eta M$. Let $u\in M'$ be unitary. By affiliation, $u$ commutes with $T$ in the domain-preserving self-adjoint sense. The commutation theorem for the Borel functional calculus of a self-adjoint operator then gives
\begin{align*}
u f(T)=f(T)u
\end{align*}
for every bounded Borel function $f:\mathbb{R}\to\mathbb{C}$.
Taking $f=\mathbb{1}_B$ for a Borel set $B\in\mathcal{B}(\mathbb{R})$, we obtain
\begin{align*}
uE_T(B)=E_T(B)u.
\end{align*}
Thus $E_T(B)$ commutes with every unitary in $M'$.
The unitaries of a unital $C^*$-algebra generate it as a linear span, so $E_T(B)$ commutes with every element of $M'$. Hence
\begin{align*}
E_T(B)\in (M')'.
\end{align*}
Since $M$ is a von Neumann algebra, the bicommutant theorem gives $(M')'=M$. Therefore $E_T(B)\in M$ for every Borel set $B\subseteq\mathbb{R}$.[/step]
custom_env
admin
[guided]Assume that $T$ is affiliated with $M$. This means that every unitary $u\in M'$ preserves the domain of $T$ and satisfies
\begin{align*}
T(u\xi)=u(T\xi)
\end{align*}
for every $\xi\in\operatorname{Dom}(T)$.
The point of using unitaries is that the spectral theorem converts this domain-level commutation relation into commutation with the bounded Borel functional calculus. More precisely, the standard commutation theorem for [self-adjoint operators](/page/Self-Adjoint%20Operators) says: if a unitary operator $u\in\mathcal{L}(H)$ commutes with a self-adjoint operator $T$ in the domain-preserving sense, then $u$ commutes with every bounded Borel function of $T$. Therefore, for every bounded Borel map $f:\mathbb{R}\to\mathbb{C}$,
\begin{align*}
u f(T)=f(T)u.
\end{align*}
Now choose the bounded Borel function $f:\mathbb{R}\to\mathbb{C}$ given by $f=\mathbb{1}_B$, where $B\in\mathcal{B}(\mathbb{R})$. The functional calculus identifies this operator with the spectral projection:
\begin{align*}
\mathbb{1}_B(T)=E_T(B).
\end{align*}
Hence
\begin{align*}
uE_T(B)=E_T(B)u
\end{align*}
for every unitary $u\in M'$.
We now translate commutation with all unitaries of $M'$ into membership in $M$. Since $M'$ is a unital $C^*$-algebra, its elements are linear combinations of unitaries. Thus an operator commuting with every unitary in $M'$ commutes with every element of $M'$. Therefore
\begin{align*}
E_T(B)\in (M')'.
\end{align*}
Finally, because $M$ is a von Neumann algebra, the bicommutant theorem gives
\begin{align*}
(M')'=M.
\end{align*}
Consequently $E_T(B)\in M$ for every Borel set $B\subseteq\mathbb{R}$.[/guided]
custom_env
admin
[step:Show spectral projections in $M$ force domain preservation]
Assume now that $E_T(B)\in M$ for every $B\in\mathcal{B}(\mathbb{R})$. Let $u\in M'$ be unitary. Since each $E_T(B)$ belongs to $M$, and $u$ commutes with every element of $M$, we have
\begin{align*}
uE_T(B)=E_T(B)u
\end{align*}
for every Borel set $B\subseteq\mathbb{R}$.
Let $\xi\in\operatorname{Dom}(T)$. For every Borel set $B\subseteq\mathbb{R}$,
\begin{align*}
\mu_{u\xi}(B)=(E_T(B)u\xi,u\xi)_H=(uE_T(B)\xi,u\xi)_H=(E_T(B)\xi,\xi)_H=\mu_\xi(B).
\end{align*}
Hence $\mu_{u\xi}=\mu_\xi$. Since $\xi\in\operatorname{Dom}(T)$,
\begin{align*}
\int_{\mathbb{R}}\lambda^2\,d\mu_\xi(\lambda)<\infty.
\end{align*}
The equality of measures gives
\begin{align*}
\int_{\mathbb{R}}\lambda^2\,d\mu_{u\xi}(\lambda)<\infty.
\end{align*}
Therefore $u\xi\in\operatorname{Dom}(T)$. Thus
\begin{align*}
u(\operatorname{Dom}(T))\subseteq\operatorname{Dom}(T).
\end{align*}
Applying the same argument to $u^{-1}\in M'$ gives equality of domains.
[/step]
custom_env
admin
[step:Commute the unitary with the spectral integral defining $T$]
For each $n\in\mathbb{N}$, define the bounded Borel function
\begin{align*}
f_n:\mathbb{R}&\to\mathbb{R}
\end{align*}
\begin{align*}
\lambda&\mapsto \lambda\,\mathbb{1}_{[-n,n]}(\lambda).
\end{align*}
Let
\begin{align*}
T_n:=f_n(T)=\int_{\mathbb{R}}f_n(\lambda)\,dE_T(\lambda)\in\mathcal{L}(H).
\end{align*}
Since $u$ commutes with every spectral projection $E_T(B)$, it commutes with every bounded Borel function of $T$. Hence
\begin{align*}
uT_n=T_nu
\end{align*}
for every $n\in\mathbb{N}$.
Let $\xi\in\operatorname{Dom}(T)$. By the spectral-integral construction of $T$,
\begin{align*}
T_n\xi\to T\xi
\end{align*}
in $H$. Since $u\xi\in\operatorname{Dom}(T)$, also
\begin{align*}
T_nu\xi\to Tu\xi
\end{align*}
in $H$. Using $T_nu=uT_n$ and the boundedness of $u$, we get
\begin{align*}
Tu\xi=\lim_{n\to\infty}T_nu\xi=\lim_{n\to\infty}uT_n\xi=uT\xi.
\end{align*}
Therefore $uT\subseteq Tu$ for every unitary $u\in M'$.
[/step]
custom_env
admin
[step:Conclude the equivalence]
The first implication showed that affiliation of $T$ with $M$ forces every spectral projection $E_T(B)$ to belong to $M$. The converse showed that if every spectral projection $E_T(B)$ belongs to $M$, then every unitary $u\in M'$ preserves $\operatorname{Dom}(T)$ and satisfies
\begin{align*}
T(u\xi)=u(T\xi)
\end{align*}
for every $\xi\in\operatorname{Dom}(T)$. This is exactly the affiliation condition. Hence $T$ is affiliated with $M$ if and only if $E_T(B)\in M$ for every Borel set $B\subseteq\mathbb{R}$.
[/step]