如何枚举silverlight中的所有输入控件

时间:2022-05-02 23:21:29

Is it possible to enumerate all the input controls in the codebehind of a silverlight user control?

是否可以枚举silverlight用户控件的代码隐藏中的所有输入控件?

For example, say you wanted to perform a form submission behind the scenes to another service. You would need to send a POST which included all of the inputs contained on your silverlight page.

例如,假设您想要在幕后将表单提交到另一个服务。您需要发送一个POST,其中包含Silverlight页面上包含的所有输入。

1 个解决方案

#1


I don't think that there is an automatic way of doing this, but you could always use VisualTreeHelper to traverse the visual tree of your Silverlight app, and pick out the value of any controls that interest you.

我认为没有自动执行此操作的方法,但您始终可以使用VisualTreeHelper遍历Silverlight应用程序的可视树,并选择您感兴趣的任何控件的值。

However, wouldn't it be easier to just bind the controls to properties on a ViewModel class? You could add a method to the class that would then build the POST request for you, based on the properties that it is managing.

但是,将控件绑定到ViewModel类的属性会不会更容易?您可以向该类添加一个方法,然后根据它管理的属性为您构建POST请求。

#1


I don't think that there is an automatic way of doing this, but you could always use VisualTreeHelper to traverse the visual tree of your Silverlight app, and pick out the value of any controls that interest you.

我认为没有自动执行此操作的方法,但您始终可以使用VisualTreeHelper遍历Silverlight应用程序的可视树,并选择您感兴趣的任何控件的值。

However, wouldn't it be easier to just bind the controls to properties on a ViewModel class? You could add a method to the class that would then build the POST request for you, based on the properties that it is managing.

但是,将控件绑定到ViewModel类的属性会不会更容易?您可以向该类添加一个方法,然后根据它管理的属性为您构建POST请求。