Compound XY2 will have ionic bonds because it is formed by transfer of electrons from atoms of element X to atoms of element Y.
On forming the compound XY2, each atom of element X that has 12 electrons with an electronic configuration of 2,8,2, donates its two electrons to give X2+ ion that has an electronic configuration of 2,8. Similarly, each atom of Y that has 17 electrons with electronic configuration 2,8,7 completes its octet by gaining one electron to form Y ion that has an electronic configuration of 2,8,8.