Found this question linked in another but I see the solution is not peffect so I post my idea of how to solve the problem. But beware: it very, very slow.
EDIT: Removed registry check method because it works only for Dx <=9 (thx @Telanor)
This method is very, very slow, but only one I figured out that is 100% accurate
private static int checkdxversion_dxdiag()
{
Process.Start("dxdiag", "/x dxv.xml");
while (!File.Exists("dxv.xml"))
Thread.Sleep(1000);
XmlDocument doc = new XmlDocument();
doc.Load("dxv.xml");
XmlNode dxd = doc.SelectSingleNode("//DxDiag");
XmlNode dxv = dxd.SelectSingleNode("//DirectXVersion");
return Convert.ToInt32(dxv.InnerText.Split(' ')[1]);
}