title: WPF vb.net Apply different button to rows in datagrid
body: <p>I am creating a column in my DataGrid with </p>
  
  <pre><code>&lt;DataGridTextColumn Header="Deploy" Binding="{Binding Deploy}" Width="100" IsReadOnly="True" CanUserSort="False"/&gt;
  </code></pre>
  
  <p>In my code, I am adding rows to the columns in my grid using </p>
  
  <pre><code>Public Structure MyRow
      Public Property Deploy As String
  End Structure
  
  
  
  MyGrid.Items.Add(New MyRow With {.Deploy= "Unlimited"})
  </code></pre>
  
  <p>What I really want to be doing, is in this Deploy field, I want to display one of two buttons dependent on a value. If I have the value 0, I want to display </p>
  
  <pre><code>&lt;Button Grid.Column="3" Padding="0" Content="A" Margin="5,8,5,12" Height="50" TextBlock.TextAlignment="Center" /&gt;
  </code></pre>
  
  <p>And if I have the value -1 I want to display</p>
  
  <pre><code>&lt;Button Grid.Column="3" Padding="0" Content="B" Margin="5,8,5,12" Height="50" TextBlock.TextAlignment="Center" /&gt;
  </code></pre>
  
  <p>Any help as to how would be appreciated! I've tried using a CellTemplateSelector</p>
  
  <pre><code>&lt;Page.Resources&gt;
      &lt;DataTemplate x:Key="ATemplate"&gt;
          &lt;Button Grid.Column="3" Padding="0" Content="A" Margin="5,8,5,12" Height="50" TextBlock.TextAlignment="Center" /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate x:Key="BTemplate"&gt;
          &lt;Button Grid.Column="3" Padding="0" Content="B" Margin="5,8,5,12" Height="50" TextBlock.TextAlignment="Center" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/Page.Resources&gt;
  
  
  ...
  &lt;DataGridTemplateColumn Header="A" Width="60" CanUserSort="False" CellTemplateSelector="{StaticResource ButtonTemplateSelector}" /&gt;
  ...
  </code></pre>
  
  <p>But then I don't know how I could then apply this template when I am adding a row to the DataGrid</p>
  
  <p>Thanks in advance</p>