Question

I am looking at Windows Store apps samples and trying to understand how some things work.

I have this code in App.xaml

<local:Apoel x:Key="apoel"/>

and this line of code in my MainPage.xaml.cs

Apoel apoellin= (Apoel)App.Current.Resources["apoel"];

I tried searching around the web but I do not know what terms to use in order to get a perfect explanation of how this works.

What exactly are these two lines of code doing?

How would it work if the constructor of the Class Apoel needed an argument?

When is the object instantiated?

Was it helpful?

Solution

It's just an assignment. In your xaml the Apoel object named apoel is being defined and

Apoel apoellin= (Apoel)App.Current.Resources["apoel"];

is just a reference assignment. No new objects are being created.

About parametrized constructors check the answer here Calling a parameterized constructor from XAML

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top