title: Casting between types in XAML
body: <p>This question is related to <a href="https://stackoverflow.com/questions/38233351/dynamically-change-xaml-binding-based-on-type">this question</a> that I asked yesterday and was unable to find an answer for. I am wondering if it is possible in XAML to cast between types. I have found [this answer][2], but I was unable to get that syntax to work. I would like to be able to downcast to a type to access some of it's properties. I would prefer a XAML only method, but if C# needs to be used I can do that as well. Any help is appreciated. Thanks</p>
  
  <p>Edit:</p>
  
  <p>Adding some code to clarify my question. </p>
  
  <p>My issue is when I try to bind to a property specific to one of the subclass unit types, XAML doesn't see it and I just get back 0's. Normally, if this was being done in C# I would just cast it and access the property, but I am not able to do that at this point in my code. The bindings are being created in C# like this:</p>
  
  <pre><code> dgtc.Header = Properties.Resources.MaxPressure;
   dgtc.MinWidth = 25;
   dgtc.Width = Properties.Settings.Default.MaxPressureColumnWidth;
   dgtc.IsReadOnly = true;
   dgtc.Binding = new Binding("Unit.MaxDepthRelativeToEntry")
   {
       Converter = new DistanceUnitsConverter()
   };
  </code></pre>
  
  <p>Where dgtc is a DataGridTextColumn. Unit.MaxDepthRelativeToEntry comes through as 0 because it is a property on the subclass of an AUnit, so XAML thinks I am trying to access an non-existent property.</p>
  
  <p>From the second link so far I have tried some of the following syntaxes:</p>
  
  <pre><code>dgtc.Binding = new Binding("AUnit.MaxDepthRelativeToEntry")
  dgtc.Binding = new   Binding("Unit(MyNameSpace:AUnit).MaxDepthRelativeToEntry")
  dgtc.Binding = new Binding("Unit(MyNameSpace:AUnit.MaxDepthRelativeToEntry)")
  </code></pre>
  
  <p>and was not able to get any of those to work. I have also tried doing this through a converter, but the issue is, I don't have the list of units available to me when I am constructing the DataGrid/ setting up the bindings/etc. so I am not able to grab the property out of the instance and return it. Does anyone know of any way that I can, preferably in XAML, get to the properties of a subclass type of the type I am binding to?</p>