简体   繁体   中英

Acess UserControl inside another UserControl

I have defined a UserControl for DateTime picking in Windows 8 store apps. The control consists of 3 checkboxes and hast a property to channel out the selected date time. When I include this control into another UserControl and name it, I am not able to access it from C# code.

 //...Page content....
 <TextBlock Text="Erledigen bis:" FontSize="16"/>
 <local:DateTimePicker Name="dtp_dueUntil"  />
 <TextBlock Text="Wichtigkeit" FontSize="16"/>
 //...Page content....

*dtp_dueUntil* is not known in my code behind file. Am I doing something awefull wrong, or just missing a point here?

You should not access controls like that, unless you have no other choice. In your case, iF you what to expose selected DateTime in your first user control, then simply declare a Dependency Property which will hold and update this value (via DataBinding or event).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM