Change VisualStudio Auto-generated Code
I have created myself a new TextBox control which inherits from the开发者_JAVA技巧 default System TextBox. If I add a datasource to my designer and in the DataSource view I can see my new text control in the list of controls I can drag onto the designer.
My Issue is when I drag the control onto the designer VS goes and creates the following code.
this.someValueTextEdit1.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.myViewModelBindingSource, "SomeValue", true));
I instead would like it to use some custom code when I drag the control onto the designer.
If your wondering why I want to do this, is so I can change the binding so that it uses linq and expression trees rather than string property values. Something like
Bind(this.someValueTextEdit, c => c.EditValue, v => v.SomeValue);
You shuld create your own CodeDomSerializer class.
Sample of usage: CodeDomSerializer Class on MSDN
精彩评论