Why would you do this? Well the most obvious use case is for translation purposes. Using multiple resource files, you can have one file for English, one for Spanish and point to the correct string in the correct file. This ensures your app can achieve that much longed for complete global saturation.
To add a resource file. Right click on your solution, click add new item. Then choose a .resw file.
Now we go into our resource file and set up our strings. It will be in the solution explorer. So open it up. On the left, you'll see a name, in the center you see a value. We'll fill these up with relevant details.
Now lets call this first one "tbOne.Text". This will fill up a text block we'll create afterwards.
Now lets create a text block in the XAML and link it back.This probably looks familiar. However, we'll need to add what is known as a uid or a unique identifier. Then we'll be able to link the resource file to the Text Block in our XAML code.<TextBlock x:Name="textBlock"/>
<TextBlock x:Name="textBlock" x:Uid="tbOne"/>
Now we have given an identifier that our Resource file recognises.
Try running the code. You should now see that it fills the text block with the content in our resource file. This is because we called it "tbOne.Text".
That is just a brief introduction. If you wish to know more, please feel to read more here.
https://msdn.microsoft.com/en-us/library/bb613571%28v=vs.110%29.aspx
No comments:
Post a Comment