Reverse Of Entered Text Using WPF

Now we will create a WPF that displays the reverse text of the originally entered text.
 
First choose Open Visual Studio, then File-> New-> Project, select the Visual C # template in the project and then select WPF App (.NET Framework), then set the name of the file name/app, if you want to change the directory Change the destination folder you want.
 
 
 

Then from the toolbox select text blocks, textboxes, and button and then drag it on the main screen.
 
 
 
 
 
 
 
 Then, change the properties of the text blocks, textboxes and the button from the properties window.
 
The XAML code for the application is as follows,
  1. <Window x:Class="Reverse_of_entered_string_using_WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Reverse_of_entered_string_using_WPF" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525">  
  2.     <Grid>  
  3.         <TextBlock x:Name="tbname" HorizontalAlignment="Left" Height="35" Margin="138,10,0,0" TextWrapping="Wrap" Text="Reverse of entered text" VerticalAlignment="Top" Width="244" FontSize="20" />  
  4.         <TextBlock x:Name="tbltext" HorizontalAlignment="Left" Height="21" Margin="137,63,0,0" TextWrapping="Wrap" Text="Enter text:" VerticalAlignment="Top" Width="122" FontSize="14" />  
  5.         <TextBlock x:Name="tblres" HorizontalAlignment="Left" Height="24" Margin="138,107,0,0" TextWrapping="Wrap" Text="Result is:" VerticalAlignment="Top" Width="121" FontSize="14" />  
  6.         <TextBox x:Name="txtdata" HorizontalAlignment="Left" Height="21" Margin="264,63,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="118" FontSize="14" />  
  7.         <TextBox x:Name="txtres" HorizontalAlignment="Left" Height="24" Margin="264,107,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="118" FontSize="14" />  
  8.         <Button x:Name="btnrev" Content="Reverse text" HorizontalAlignment="Left" Height="33" Margin="186,148,0,0" VerticalAlignment="Top" Width="106" FontSize="14" /> </Grid>  
  9. </Window>  
 
 
Then your screen appears like this
 
 
  
Now open the .cs file and write the following code in it.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Windows;  
  7. using System.Windows.Controls;  
  8. using System.Windows.Data;  
  9. using System.Windows.Documents;  
  10. using System.Windows.Input;  
  11. using System.Windows.Media;  
  12. using System.Windows.Media.Imaging;  
  13. using System.Windows.Navigation;  
  14. using System.Windows.Shapes;  
  15. namespace Reverse_of_entered_string_using_WPF {  
  16.     /// <summary>  
  17.     /// Interaction logic for MainWindow.xaml  
  18.     /// </summary>  
  19.     public partial class MainWindow: Window {  
  20.         public MainWindow() {  
  21.             InitializeComponent();  
  22.         }  
  23.         private void btnrev_Click(object sender, RoutedEventArgs e) {  
  24.             string data = txtdata.Text;  
  25.             char[] charc = data.ToCharArray();  
  26.             Array.Reverse(charc);  
  27.             int i;  
  28.             string empytstr = string.Empty;  
  29.             for (i = 0; i < charc.Length; i++) {  
  30.                 empytstr += charc[i];  
  31.             }  
  32.             txtres.Text = empytstr.ToString();  
  33.         }  
  34.     }  
  35. }   
 
In the above code, I have taken a string and transformed that into a character array. Then, I have reversed that character array and in an empty string, concatenated the reversed array elements. This displays the reversed text.
 
Now run the WPF application. The outputs will be as follows.

 
  
In the first case, I have reversed the text and in the second case, I have reversed the decimal values.
 
Now we have successfully created a WPF application that displays the reverse of entered text.
Next Recommended Reading Colored Label Text Using WPF