If a person shows off in his worship, then this falls under four categories.
- If showing off is the driving force behind doing the act of worship, then the worship is invalid. It is reported in the hadeeth qudsi that Allaah (سُبْحَانَهُ وَ تَعَالَى) said,
“I am the One, One Who does not stand in need of a partner. If anyone does anything in which he associates anyone else with Me, I shall abandon him with one whom he associates with Allaah.” 
2. If a person begins his worship sincerely and showing off occurs later at which point he tries to stop showing off, then his worship is valid.
Otherwise, if he continues and does not attempt to ward it off, inclining towards it, then one examines whether the latter part of this worship depends on its earlier part or vice verse. For example, with salaah and wudhu, these worships would become invalid in this case.
On the other hand, if the worship is distinguished such that the parts are independent, then whatever occurred before showing off is valid, and whatever occurred after the person began to show off is invalid. For instance, a person gives $50 in charity sincerely. Later, he gives $500 to show off. His first donation is valid while the $500 are invalid.
3. If a person begins to show off after concluding the worship, then the worship is valid. However, this nullifies the reward for the worship.
Allaah (سُبْحَانَهُ وَ تَعَالَى) said (in the translation of the meaning):
“O you who believe! Do not render in vain your Sadaqah (charity) by reminders of your generosity or by injury, like him who spends his wealth to be seen of men, and he does not believe in Allaah, nor in the Last Day. His likeness is the likeness of a smooth rock on which is a little dust; on it falls heavy rain which leaves it bare. They are not able to do anything with what they have earned. And Allaah does not guide the disbelieving people.”
Surah al-Baqarah (2:264)
4. The showing off is in the descriptive manner of the worship, not its origin. As such, the person initiates the action for the sake of Allaah (سُبْحَانَهُ وَ تَعَالَى) but shows off in its description.
For instance, someone begins his salaah sincerely, but he hears someone come, at which point he begins to perfect his salaah more than normal. In this situation, all of that which he added to the sincere part of the salaah will have no reward.
 Reported in Saheeh Muslim, (English translation no. 7114, book 42)
Source: Al-Qawaa’id wal-Usool al-Jaami’ah wal-_Furooq watTaqaaseem al-Badee’ah an-Naafi’ah