My 327 did that once when I forgot to tighten the locking screw down after installing it. It took a few hours of flight to work loose enough to shut off, but came right back to life when it was pushed into place.
Jim
You may wanna check all your terminal's connections.
I had the same problem as you and all it was , was a slightly loose connection to a terminal in the harmess...I had to pull on it to make it come off but it was enough to turn the Txpr off with the engine vibration...Worked fine on the ground with the engine Off...
Good luck
Bruno