Based on the Treaty of Vienna in 1506, Emperor Maximilian was entitled to the Hungarian heritage. In addition, he organized a double wedding with king Vladislav II. The grandchildren of the Emperor, Ferdinand and Mary, married the king's children Anne and Louis. By that, mutual hereditary titles in the event of extinction were secured.
Already in the hereditary contract, Mary was promised to the not yet born son of Vladislav. At the time of the wedding in 1515, it was not yet decided which one of his grandsons should marry Anne. Therefore, Emperor Maximilian performed as a proxy. In 1526, Mary's husband Louis II died at the age of 20 during the Battle of Mohács which brought Hungary and Bohemia in the possession of the Habsburg.