Working with Special Symbols in WPF Application

Updated on     Kisan Patel

In WPF, if you want to display some symbols, such as <, > and &, you cannot write them directly in your WPF application, because these symbols are already assigned to perform specific task.

So you need to use special HTML code in your WPF application to display symbols.

MainWindow.xaml

<Window x:Class="WPFStackPanelDemo.MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="MainWindow" Height="350" Width="525">
     <Grid>
          <TextBlock Height="30" VerticalAlignment="Top" HorizontalAlignment="Left"
             Margin="20, 20, 0, 0">
                    &gt; = Greated than symbol.
          </TextBlock>
          <TextBlock Height="30" VerticalAlignment="Top" HorizontalAlignment="Left"
             Margin="20, 60, 0, 0">
                    &amp; = Apersand symbol.
          </TextBlock>
          <TextBlock Height="30" VerticalAlignment="Top" HorizontalAlignment="Left"
             Margin="20, 90, 0, 0">
                    &quot; Life is Beautiful &quot;.
          </TextBlock>
     </Grid>
</Window>

The output of the above XAML code will be:

special-symbols-demo-wpf


WPF

Leave a Reply