It is narrated from Sayyiduna Shaddad bin Aws (may Allah be pleased with him) that he said: I heard the Messenger of Allah (peace and blessings be upon him) say: "Whoever prays to show off has committed shirk (associating partners with Allah), whoever fasts to show off has committed shirk, and whoever gives charity to show off has committed shirk." At this Sayyiduna Awf bin Malik (may Allah be pleased with him) asked: "Does Allah, the Mighty and Majestic, not take from such a deed the part that was purely for Him, accept it, and leave what was other than that (done for show)?" Sayyiduna Shaddad (may Allah be pleased with him) said: I heard the Messenger of Allah (peace and blessings be upon him) say: "Allah, the Blessed and Exalted, has said: I am the best of partners - or sharers - (among those set up alongside Me). Whoever associates anyone with Me, his deed, whether little or much, belongs to that partner of Mine, and I am free of him."
I say: Imam al-Bayhaqi recorded it in his Sunan through Abd al-Hamid bin Bahram, and he mentioned it in the same way.
Hadith Referenceإتحاف الخيرة المهرة بزوائد المسانيد العشرة / كتاب الصلاة / 741
Hadith Gradingمحدثین:إسناده حسن؛ عبد الحميد بن بهرام أثبت الناس في شهر بن حوشب