How To Apply Border Resource To TextBlock Control In UWP With XAML And C#

Before reading this article, please go through the following article.

  1. Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015

Reading this article, you can learn how to apply Border resource to TextBlock Control in Universal Windows Apps development with XAML and Visual C#.

The following important tools are required for developing UWP,

  1. Windows 10 (Recommended)
  2. Visual Studio 2015 Community Edition (It is a free software available online)

Now, we can discuss steps of  App development.

Step 1- Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank App -> Give a suitable name for your App (UWPBorderResource)->OK.


Step 2- Choose the Target and Minimum platform version your Universal Windows Application will support. Now, the project creates App.xaml and MainPage.xaml files.


Add TextBlock control and change the Name and Text property for title.


Step 3 - Add the following code for creating Local Resource for TextBlock. Then, add the TextBlock Control and set the text property as local resource string, named as Border.

  1. <Page.Resources>  
  2.    <x:String x:Key="Border">No Border</x:String>  
  3. </Page.Resources>  

Step 4 - Add border code and inside the border resource, use the same local resource string name (border string) and new content.
 Add border code

Add new Text Block Control, change name property, and remove the text content.

Text Block Control

Step 5- Add the following code in the MainPage.xaml.cs constructor method,
  1. string s = (string)newborder.Resources["Border"];  
  2. tblInborder.Text = s;  

Step 6 - Deploy your app in Local Machine, and the output of the UWPBorderResource app.


Now, you have successfully created and applied Border Resource to TextBlock Control in Visual C# - UWP environment.