Let's start with an infinitive: it has a form "to..." - only sentences C and D have a phrase like this, so we can exclude other options.
Among those, C does not have a gerund, which is a verbal form: "dreaming" has a function of a noun there.
So the correct answer is the remaining one, D.