开发者

WPF: access controls from usercontrol

I have a usercontrol whit a RichTextBox control and a TreeView, and I want to bind a c开发者_JS百科ommands like Copy, Cut, Paste etc which are in Window not in usercontrol but I dont know how to access Elements from usercontrol? Any ideas?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜