title: Bind DataGridTextColumn to method WPF
body: <p>Is it possible to bind a DataGridTextColumn to a method in my xaml.cs?</p>
  
  <p>This is my XAML</p>
  
  <pre><code>           &lt;my:DataGrid.Columns&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding IdItem}" Header="Id Item" Width="150" IsReadOnly="True"/&gt;
  
                  &lt;my:DataGridTextColumn Binding="{Binding concatenarMoneda}" Header="Costo" Width="*"/&gt;
              &lt;/my:DataGrid.Columns&gt;
  </code></pre>
  
  <p>and I want to bind the second column to the following function</p>
  
  <pre><code>private string concatenarMoneda
      {
          get { 
              return viewModel.Registro.Costo.ToString() + " " + viewModel.Registro.SOSMoneda.Descripcion; 
          }
      }
  </code></pre>
  
  <p>This should result in two properties being concatenated in the same column</p>
  
  <p>I have seen this working with a textblock but it is not working in this case.</p>
  
  <p>See <a href="https://stackoverflow.com/questions/16467043/bind-property-to-method">Bind property to method</a></p>
  
  <p><strong>UPDATE</strong> more code as requested</p>
  
  <p>this is my whole grid</p>
  
  <pre><code>  &lt;Grid Grid.Row="2" Background="{DynamicResource GrisOscuro}"&gt;
          &lt;my:DataGrid EnableRowVirtualization="False" x:Name="DataGridDatos" Margin="32"
                       HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                       AutoGenerateColumns="False" Background="White"                    
                       SelectionChanged="DataGridDatos_SelectionChanged"
                       SelectedItem="{Binding Registro}"
                       ItemsSource="{Binding Registros}"
                       IsEnabled="{Binding DataGridDatosEstado}"
                       SelectedIndex="{Binding IndiceActual}"
                       IsReadOnly="True"&gt;
              &lt;my:DataGrid.Columns&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding IdItem}" Header="Id Item" Width="150" IsReadOnly="True"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding SOSProveedor.Nombre}" Header="Proveedor" Width="150" IsReadOnly="True"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding SOSServicio.Descripcion}" Header="Servicio" Width="*"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding SOSUbicacion.Descripcion}" Header="Ubicacion" Width="*"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding SOSTipoPagoItem.Descripcion}" Header="Tipo Pago Item" Width="*"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding FechaInicioVigencia , StringFormat={}{0:dd/MM/yy}}" Header="Fecha Inicio" Width="*"/&gt;
                  &lt;my:DataGridTextColumn Binding="{Binding Estatus}" Header="Estatus" Width="*"/&gt;
                  &lt;my:DataGridTextColumn  Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, 
              Path=concatenarMoneda,Mode=OneWay}" Header="Costo" Width="*"/&gt;
              &lt;/my:DataGrid.Columns&gt;
          &lt;/my:DataGrid&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>that grid is sorrounded by  which is the parent element within the XAML</p>
  
  <p>on the other in my xaml.cs I've got the <strong>concatenarMoneda</strong> function that I showed above</p>
  
  <p>and my ViewModel brings all the data from the Model... using methods such as this</p>
  
  <pre><code>public ObservableCollection&lt;SOSItem&gt; Items
      {
          get
          {
              if (_items == null)
              {
                  _items = new ObservableCollection&lt;SOSItem&gt;(db.SOSItems.Select(AppRow =&gt; AppRow));
              }
              return _items;
          }
          set
          {
              _items = value;
              NotifyPropertyChanged("Items");
          }
      }
  </code></pre>
  
  <p>Maybe the ancestor type you suggest should be other than </p>
  
  <pre><code>  AncestorType={x:Type Window}
  </code></pre>
  
  <p>?</p>