He was born in Milan, where his father was a chef and butler at the Milanese court. He was apprenticed at an early age to the goldsmith and medalist,, who was impressed by his talent for drawing and convinced him to enroll at the Brera Academy. He was accepted there in 1831 and studied, successively, with Pompeo Marchesi, Luigi Sabatelli and Francesco Hayez, who had the most influence on his style. At this time, he favored scenes from the Bible or classical history. In 1840, he obtained a commission from agents representing Emperor Ferdinand I to paint a scene depicting Saul being anointed king by the prophetSamuel, for display at the Imperial Gallery in Vienna. Over the next few years, he gradually abandoned history painting in favor of genre scenes, which were then in style among liberal members of the Milanese aristocracy. His mentor, Hayez, assisted him in obtaining noble patrons. In 1843, he married Emilia Trezzini, the sister of one of his students, Angelo Trezzini. Five years later, following his participation in the Five Days of Milan he, his wife and brother Gerolamo were forced to flee to Ticino, to escape the reprisals that followed. In 1850, when it was safe, they returned and settled in Florence. In 1854, he was named a "Socio d’Arte" at the Brera Academy. The following year, he held his first exhibition outside Italy at the Exposition Universelle in Paris, which was considered a great success. In 1860, he was named a judge for a major patriotic art competition sponsored by Bettino Ricasoli. Later that year, he began working on several scenes related to the Armistice of Villafranca; one of which was commissioned by King Victor Emmanuel II and earned him a title in the Order of Saints Maurice and Lazarus. In 1863, he became Director of the Brera Academy and no longer participated in their annual exhibitions. Ten years later, at the World Exposition in Vienna, he was awarded a gold medal for Un dramma domestico, a critique of society in post-unification Italy. After that, his paintings became rather gloomy and melancholy. Although suffering from a serious eye ailment, he was able to participate in the Exposition Universelle of 1878, but died later that year, in Milan.