title: WPF convert boolean binding to a string like Yes or No
body: <p>As my Title says I need to write in my DataGrid instead of True or False Yes/No for boolean value I am getting from database,</p>
  
  <p>I've been researching and I've found some helpers like :</p>
  
  <pre><code>public class BoolToValueConverter&lt;T&gt; : IValueConverter
  {
      public T FalseValue { get; set; }
      public T TrueValue { get; set; }
  
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value == null)
              return FalseValue;
          else
              return (bool)value ? TrueValue : FalseValue;
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          return value != null ? value.Equals(TrueValue) : false;
      }
  }
  </code></pre>
  
  <p>But question is how to apply this correctly in XAML,</p>
  
  <p>I tried adding this to my XAML:</p>
  
  <pre><code>&lt;local:BoolToStringConverter x:Key="BooleanToStringConverter" FalseValue="No" TrueValue="Yes" /&gt;
  </code></pre>
  
  <p>But than I got following errors:</p>
  
  <blockquote>
    <p>Error 2   ''local' is an undeclared prefix. Line 13, position 10.' XML
    is not valid. </p>
    
    <p>Error 4   BoolToStringConverter is not supported in a Windows
    Presentation Foundation (WPF) project.    </p>
    
    <p>Error 7   The "Key" attribute can only be used on an element that is
    contained in "IDictionary".</p>
  </blockquote>
  
  <p>So my questions is how to make this works in my XAML, probably I need to include something or whatever, I am really new to WPF so right now it is really hard for me to find solutiokn :/</p>
  
  <p>Anyway
  Thanks guys,
  Cheers</p>
  
  <p>EDIT: (MY XAML CODE)</p>
  
  <pre><code>&lt;Window x:Class="MyProject.Forms.Products"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:sys="clr-namespace:System;assembly=mscorlib"
          Title="Products" Height="768" Width="1024"&gt;
      &lt;Grid&gt;
            &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="60" /&gt;
                          &lt;RowDefinition /&gt;
                          &lt;RowDefinition Height="60" /&gt;
            &lt;/Grid.RowDefinitions&gt;
  
          &lt;DataGrid Grid.Row="1" IsReadOnly="True" Name="dtgProducts" ScrollViewer.CanContentScroll="False" EnableRowVirtualization ="True" EnableColumnVirtualization = "True" HorizontalGridLinesBrush="#d3d3d3" AlternatingRowBackground="#E0E4E5" AlternationCount="2"  GridLinesVisibility="Horizontal" FontSize="16" RowHeight="30" SelectionUnit="FullRow" Background="White" Margin="5,0" AutoGenerateColumns="False" ItemsSource="{Binding}" RowHeaderWidth="0" VerticalGridLinesBrush="#0091EA" CanUserAddRows="False"&gt;
                  &lt;DataGrid.CellStyle&gt;
                      &lt;StaticResource ResourceKey="DataGridCentering"/&gt;
                  &lt;/DataGrid.CellStyle&gt;
  
                  &lt;DataGrid.Resources&gt;
  
                      &lt;Style TargetType="{x:Type DataGridColumnHeader}"&gt;
                          &lt;Setter Property="Background" Value="#0091EA"/&gt;
                          &lt;Setter Property="Opacity" Value="1"/&gt;
                          &lt;Setter Property="Foreground" Value="White"/&gt;
                          &lt;Setter Property="HorizontalContentAlignment" Value="Center" /&gt;
                          &lt;Setter Property="FontSize" Value="16"/&gt;
                          &lt;Setter Property="FontFamily" Value="Arial"/&gt;
                          &lt;Setter Property="Height" Value="40"/&gt;
                      &lt;/Style&gt;
  
                      &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                     Color="LightBlue"/&gt;
  
                  &lt;/DataGrid.Resources&gt;   
  
                  &lt;DataGrid.Columns&gt;
                  &lt;DataGridTextColumn Binding="{Binding ProductTitle}"        Header="ProductName"  Foreground="Black"  FontSize="15" FontFamily="Verdana"  Width="10*"/&gt;
                  &lt;DataGridTextColumn Binding="{Binding IsNew}" Header="Is it new product(Yes/No)."  Foreground="Black"  FontSize="15" FontFamily="Verdana"  Width="10*"/&gt;
              &lt;/DataGrid.Columns&gt;
  
      &lt;/DataGrid&gt;
  
      &lt;/Grid&gt;
  
  &lt;/Window&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>INCLUDED IN RESOURCES OF DATAGRID</p>
  
  <p><a href="https://i.stack.imgur.com/LuRPC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LuRPC.jpg" alt="enter image description here"></a></p>
  
  <p>INCLUDED ON TOP OF DOCUMENT:</p>
  
  <p><a href="https://i.stack.imgur.com/tGWDc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tGWDc.jpg" alt="enter image description here"></a></p>