Define And Use Local Resource In UWP With XAML And C#

Introduction

In Visual C# Environment, a number of predefined system resources are available. Local resources are user defined and you can use your local project. In this article, we are concentrating on how to create a string local resource and how to use use the local resource in Textblock title.

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 Define and use local resources 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 step by step app development.

Step 1 - Open Visual studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank App -> Give the Suitable Name for your App (UWPDefineResource)->OK.



Step 2 - Choose the Target and minimum platform version your Windows Universal Application will support. After the Project create App.xaml and MainPage.xaml.



Step 3 - Add the following code for creating Local Resource, (Name is MyResource)

  1. <Page.Resources>  
  2.    <x:String x:Key="MyResource">Test Resource!....</x:String>  
  3. </Page.Resource>  


Add TextBlock control and change the Name and text property,



Step 4 - Add TextBlock control and change the Name and set the text property as Local resource and set as MyResource,



Step 5 - After setting the MyResource in TextBlock is,



Step 6 - Deploy your App in Local Machine, and the output of the UWPDefineResource App is,



Summary - Now you have successfully created and tested your defined local Resource in Visual C# - UWP environment.

 

Up Next
    Ebook Download
    View all
    Learn
    View all