views:

337

answers:

3

Hello! I have a usercontrol whit a RichTextBox control and a TreeView, and I want to bind a commands like Copy, Cut, Paste etc which are in Window not in usercontrol but I dont know how to access Elements from usercontrol? Any ideas?

A: 

You have to add a namespace to your XAML file and add your usercontrol with the given namespace prefix

as such:

xlmns:myuserctrl = "assemblyreference here"

Make sure you give your usercontrol a name which you can access in your code-behind.

You should then be able to access your controls from that variable inside your code-behind. If not, create some properties in the usercontrol class referencing the controls inside the user control.

Tony
A: 

From code-behind I hava access to the richtextbox like that nameofusercontrol.nameofrichtextbox but I dont know how to access from XAML.

can I do it with XAML?

Ilian
For future reference, you should edit your original question rather than posting an answer to ask something!
Will Vousden
A: 

There's no straightforward way of accessing child elements of user controls in XAML. However you can get creative and implement a custom type descriptor that exposes control fields as properties, which you can then bind to from the elements outside of the user control.

Aviad P.