Answer
$F=g\tan\theta\left[m_1+m_2\right]$
Work Step by Step
First, we need to draw a force diagram of both objects, as we see below.
As we see in the figures below, there are no friction forces between the surfaces as the author assumed and the acceleration of the two blocks is the same.
Applying Newton's second law on block 1;
$$\sum F_{x1}=F_{2\;on\;1}\sin\theta=m_1a_x$$
Thus,
$$F_{2\;on\;1}\sin\theta=m_1a_x\tag 1$$
$$\sum F_{y1}=F_{2\;on\;1}\cos\theta-m_1g=m_1 a_y=m_1(0)=0$$
Thus,
$$F_{2\;on\;1}\cos\theta=m_1g$$
$$F_{2\;on\;1}=\dfrac{m_1g}{\cos\theta}\tag 2$$
Plugging into (1);
$$\dfrac{m_1g}{\cos\theta}\;\sin\theta=m_1a_x $$
$$ \color{red}{\bf\not}m_1g \tan\theta=\color{red}{\bf\not}m_1a_x $$
Hence,
$$a_x=g \tan\theta\tag 3$$
Applying Newton's second law on block 2;
$$\sum F_{x2}=F-F_{1\;on\;2}\sin\theta=m_2a_x$$
$$F-F_{1\;on\;2}\sin\theta=m_2a_x$$
We can see that the normal force exerted by block 1 on block 2 and the normal force exerted by block 1 on block 2 are an action-reaction pair.
So they have the same magnitude.
Thus, plugging from (2);
$$F-\dfrac{m_1g}{\cos\theta}\;\sin\theta=m_2a_x$$
$$F- m_1g \tan\theta=m_2a_x$$
$$F=m_2a_x+ m_1g \tan\theta $$
Plugging $a_3$ from (3);
$$F=m_2g \tan\theta+ m_1g \tan\theta $$
Therefore,
$$\boxed{F=g\tan\theta\left[m_1+m_2\right] }$$