GetTemplateChild

Feb 21, 2011 at 5:31 AM

How can i use the GetTemplateChild method(protected method) in the Caliburn.Micro Framework to get the control object (e.g x:name is "btn") and modify its content.

Coordinator
Feb 21, 2011 at 1:24 PM

Can you provide some additional nformation? I'm not sure I understand the scenario.

Feb 22, 2011 at 3:37 AM
Edited Feb 22, 2011 at 3:38 AM

Hi EisenbergEffect,

   Thanks for you reply the post, Okay let me detail the scenario:

   If i have a button control  in the login.xaml which x:name="btn" then i want to change it's Content,how can i do it?

  Under my understanding, i know there is a GetTemplateChild pretected method in  Microsoft.Windows.Controls namespace if i inherit Control class.

  Please give me some suggestion,thank you in advance.

 

 

 

  

Feb 22, 2011 at 10:21 AM
Edited Feb 22, 2011 at 10:22 AM

I'm afraid you are following a bad approach.
GetTemplateChild is intended to be used by custom controls author to get a reference to primitive parts used to compose a control's template.

The typical MVVM way of changing the content of a Button or a Label is to create a property in the View Model and bind it in the view using a binding.
All changes made to the View Model property are automatically reflected into the View.

Caliburn.Micro is NOT direclty involved in this mechanism: it just simplifies the setup of the bindings using some conventions, thus avoiding you to explicitly write the bindings in Xaml (along with MANY other things, actually).

I suggest you to have a look at the samples/Caliburn.Micro.Hello sample in the source code and to the conventions documentation.
You may also want to get a deeper knowledge about MVVM; here is a Rob's post containing many interesting source: http://devlicio.us/blogs/rob_eisenberg/archive/2010/05/01/mvvm-study-interlude.aspx

Feb 22, 2011 at 1:08 PM
Edited Feb 22, 2011 at 2:20 PM

Hi  marcoamendola,

I'm very appreciate what you have done for me.

B&R

Feb 22, 2011 at 4:06 PM

You're welcome :-)