How do you make your leg stay put? You don't. Gravity does. If your leg doesn't stay put, then you are messing with it and riding your stirrups instead of the horse. Get off the stirrups and on to the horse.
For me personally, I sort of had to come full circle. First I pushed and braced into my stirrups. My toe would often point down and turn my stirrup into a pendulum. Then I pretty much abandoned my stirrups and tried to work on my "seat." Then I learned that if you sit down onto your horse you are susceptible to every thing your horse does. You can't actually abandon the stirrups and be able to zig zag down a narrow trail at a high rate of speed. Your butt just isn't capable of that kind of balance.
So I had to learn that basically the amount of muscle tension is the same from your waist down. Every muscle is lightly
contracted so you basically "hover" on your horse. It appears that you sit down on the saddle, but in reality it is as if you are straddling a chair but putting only part of your weight on the chair so if someone yanked the chair out from under you, you would still remain standing up. This creates an incredibly secure position. It requires no more effort than it takes to stand relaxed in your living room.
It is hard to describe - but you can sit down on your horse without weight in the stirrups, you can stand up in the stirrups, or you can "hover" in between. This is not gravity pulling the weight of your legs only, but gravity pulling the weight of your body (evenly divided between your seat and your stirrups, spread out along the length of your lightly contacting leg).
If you keep your weight like this when you ride it will become completely automatic in a very short time. You won't lose your stirrups even if your horse has the choppiest trot.