Initializing a control in a UserControl


hi, user control has property, currentcompound, contains value need display in hyperlink. however, when check value of property during user control constructor value null. how can properties value , use in content of hyperlink?

my code below.

the code invoked : <users:userctrl currentcompound="compound1" />

i have noticed @ line 24 property currentcompound empty , @ line 40 value contain correct string, since callback method static cannot access hyperlink's content property.

1      public string currentcompound
2 {
3 get
4 {
5 return (string)getvalue(currentcompoundproperty);
6 }
7 set
8 {
9 setvalue(currentcompoundproperty, value);
10 this.hypercmpdbtn.content = value;
11 }
12 }
13
14 public static dependencyproperty currentcompoundproperty =
15 dependencyproperty.register("currentcompound", typeof(string), typeof(compoundcontrol),
16 new propertymetadata("", currentcompound_propertychangedcallback));
17
18 private string identifier { get; set; }
19
20 public compoundcontrol()
21 {
22 initializecomponent();
23 identifier = generateid(); // create unique id instance of control
24 string x = this.currentcompound;
25 }
26
27
28 private void hypercmpdbtn_click(object sender, routedeventargs e)
29 {
30 darttable dt = darttable.instance;
31 dt.userselectedcompound = currentcompound;
32 // jump compound detail page
33 system.windows.browser.htmlpage.window.navigate(new uri(constants.page_compound_module_link, urikind.relativeorabsolute));
34 }
35
36
37 // called when currentcompound changed via xaml exposed property
38 private static void currentcompound_propertychangedcallback(dependencyobject d, dependencypropertychangedeventargs e)
39 {
40 var value = e.newvalue as string;
41 }
 the xaml contains hyperlinkbutton control:
< hyperlinkbutton name="hypercmdbtn" />
 

you can replace "this" first parameter in method, direct object.

(d as customobject).hypercmpdbtn.content = value;
 


Silverlight  >  Getting Started with Silverlight



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........