Reputation: 2786
I have a static resource in my Page1.xaml.
<Page.Resources>
<x:String x:Key="PageName">Page 1</x:String>
</Page.Resources>
I want to access this resource in the code, but can't see how to do it. I'm sure I'm sure I'm missing something simple.
My MainPage
uses a single Frame
for navigation and the MainPage
has the title of the page that is displayed in the Frame
.
I would have thought I could do something like this in my MainPage.xaml.cs
string title = "NOT SET!";
rootFrame.Resources.TryGetValue("PageName", out title);
pageTitle.Text = title;
Where rootFrame
is the frame that is displaying the Page1
.
However this doesn't compile as TryGetValue
takes an object
as its first parameter.
Upvotes: 1
Views: 1488
Reputation: 2786
Here is how I did in the end.
object title = "NOT SET!";
object key = "PageName";
var page = (Page)rootFrame.Content;
page.Resources.TryGetValue(key, out title);
Upvotes: 3