title: WPF why methodInfo = object.GetType().GetMethod("SelectionChanged") ..... return a null value?
body: <p>I have a form in wpf , at runtime in the Load event add the following controls from XAML string</p>
  
  <pre><code>// load Canvas
  sXAML = "&lt;Canvas  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'";            
  sXAML += " Height=\"Auto\" Name=\"canvasMain\" Width=\"Auto\"&gt;";
  sXAML += " &lt;/Canvas&gt;";
  
  XmlDocument xdoc = new XmlDocument();
  xdoc.LoadXml(sXAML);
  XmlTextReader xmlReader = new XmlTextReader(new StringReader(xdoc.OuterXml));
  object obj = XamlReader.Load(xmlReader);
  
  if (obj != null)
  {
   Canvas cnv = obj as Canvas;
   this.AddChild(cnv);
          this.RegisterName(cnv.Name, cnv);
  }
  </code></pre>
  
  <p>then add a Canvas a dataGrid control </p>
  
  <pre><code>// load dataGrid             
  sXAML = "&lt;DataGrid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'";
  sXAML += " AutoGenerateColumns=\"True\" Height=\"207\" HorizontalAlignment=\"Left\" Margin=\"140,6,0,0\" Name=\"dtgListServer\" VerticalAlignment=\"Top\" Width=\"751\" AlternatingRowBackground=\"LightCyan\"&gt;";
  sXAML += "&lt;/DataGrid&gt;";
  
  XmlDocument xdoc = new XmlDocument();
  xdoc.LoadXml(sXAML);
  XmlTextReader xmlReader = new XmlTextReader(new StringReader(xdoc.OuterXml));
  object obj = XamlReader.Load(xmlReader);
  
  if (obj != null)
  {
   DataGrid dtg = obj as DataGrid;
          cnv.Children.Add(dtg);
          cnv.RegisterName(dtg.Name, dtg);
  }
  </code></pre>
  
  <p>I must now add events to DataGrid  control , but the method GetMethod always returns null</p>
  
  <pre><code>EventInfo ei = dtg.GetType().GetEvent(eventname);
  MethodInfo mi = dtg.GetType().GetMethod(methodname, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
  Delegate del = Delegate.CreateDelegate(ei.EventHandlerType, this, mi);
  ei.AddEventHandler(dtg, del);
  </code></pre>
  
  <p>of course I tried with the method "SelectionChanged" and more flag but the result is always null
  anyone can help me and indicate where is my mistake
  I thank you in advance</p>