When it comes to prepositions (or grammatical cases in inflected languages) there are no rigid rules - their use is idiosyncratic to each specific language.
As a general guideline one could use the overlap of functions of prepositions in the target language with those in the language one already knows, e.g., à can be often translated as to, whereas de can be translated as of/about, so we have mappings like:
talk to somebody about something -> parler à quelqu'un de quelque chose
However, one can readily come with examples where this rule breaks, like
try to do something -> essayer de faire quelque chose
think of somebody-> pense à quelqu'un
And then, of course, there are such completely diverging uses as:
tarte aux pommes -> apple pie (pie with apples)
One can however to learn about specific grammatical situations, mandating use of one or another preposition:
- the preposition mandated by verbs: one simply have to memorize which verb uses which preposition, like dire à quelqu'un, parler à quelqu'un, essayer de faire quelque chose, etc.
- genitive structure / possession: in French it is mostly built using de: le fils de professeur, le maire de la ville, etc.
- direction of movement: aller à Paris = go to Paris, venir de Paris = come from Paris
- other specific uses like pain au chocolat/raisin
- and so on.