WPF-如何从自定义用户控件访问页面中的元素 [英] WPF - How to access an element in page from a Custom User Control
本文介绍了WPF-如何从自定义用户控件访问页面中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个导航应用程序,并且有一个自定义控件,该控件将出现在每个页面上.
在此用户控件上,我将具有一个将网格旋转180d的按钮,但是我不知道如何从我的用户控件访问网格(或任何其他元素).
有帮助吗?
谢谢
Daniel
Hi,
I have a Navigation Application and I have a custom Control which is going to be on every page.
On this User Control I will have a button which will turn the grid by 180d, but I don''t know how I can access the grid (or any other element) from my user control.
Any Help?
Thanks
Daniel
推荐答案
正确的方法是让父表单为用户控件上的按钮订阅button-click事件.我认为您可能必须将按钮更改为公开按钮才能执行此操作,但是我不记得是否确实需要这样做.
完成此操作后,只需从事件处理程序中以主要形式旋转网格即可.
The proper way to do it is to have the parent form subscribe to the button-click event for the button on the user control. I think you may have to change the button to be public in order to do it, but I don''t remember exactly if that''s necessary.
Once you''ve done that, simply rotate the grid from the event handler in the main form.
这篇关于WPF-如何从自定义用户控件访问页面中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文