Monday, April 16, 2018

UWP: How do you access Page resources by code in an UWP app?-Part 2

In the previous example you have seen how to access page resource via code. As mentioned earlier, resource can also be stored in other FrameworkElements such as the 'Border' in this present example. The x:key for the 'Border' is the same as that of the Page's resource.

How do we call the resource stored in the Framework Element BORDER?

Here is the MainPage.Xaml for this post.


PageResrcs_3

It also shows the textbox, the target for the code (happens to be left out in the MSDN article here).
Both the Framework Elements Page and Border has the same x:Key.

The code to access the Page resource is as shown here (same as previous post).


PageResrcs_3

If you want to access the resource in the BORDER, you uncomment and comment code as suggested.
The app displays as shown when run.


PageResrcs_5



No comments: