The lattice structure of dilithium is such that, when in an EM field, it functions as a sort of "magnetic bottle" on a microscale, holding the antiparticles within the gaps in the atomic lattice so that they don't annihilate the crystal's particles.
^This reminds me of a hypothetical crystal-based, *non-energy consuming* antimatter storage device I read about once, a long, long time ago in Analog magazine (this was back in the late 80's, I believe) - in Analog they called this proposed crystal storage something like 'real-life dilithium crystals', but they weren't made of any kind of lithium (as far as I remember) - nor is that what dilithium crystals do in Trek. They don't store anti-matter.
But...they idea was to store that antimatter as individual particles in a crystal lattice. but not just any crystal - but a specially engineered sort of crystal that, like memory materials, changed it's crystalline structure when either heat and/or electric or magnetic charge was applied to it. In one phase the crystal lattice would act as a cage, like you describe above, holding the individual antimatter particles without touching the walls of the crystal lattice itself (suspending it, I guess, using natural atomic or molecular attraction and repulsion forces). But when a charge was applied, the crystal lattice would open up, allowing the anti-matter atoms to flow or be moved freely through it and be extracted. But, as a fail-safe, the crystal structure would revert back to it's cage arrangement if too much heat or energy was applied to it...or, in this case, generated by too many matter/anti-matter reactions - thereby re-containing the anti-matter. (the heat would be generated by millions of tiny little matter-anti-matter reactions...enough to generate heat or an electric current or something, but not near enough to cause a huge nuclear-bomb sized kaboom.)
This property would allow the crystal to maintain containment integrity without the need for a constant supply of energy, so you wouldn't have to worry about catastrophic containment failure if the power failed, like you would with a shield or electromagnetic containment device! The containment would be self-maintaining.
And the matter-anti-matter reaction could be regulated by the application of magnetic or electric fields...or maybe even self regulating if the crystal lattice was "open" naturally, and "closed' when heat or an electric current or magnetic field was applied: The crystal would open...matter and anti-matter would react...the crystal would close...the temp or whatever would drop off...the crystal would open...etc, etc...(maybe.)
^So I suppose the same properties of this crystal that contain antimatter could be used to perhaps regulate (and maybe even channel the anti-matter reaction.
Of course, nobody knows if such a crystal exists or can be created - or how to create it. It was all just hypothetical.