VB代码视图与WPF代码视图 [英] VB code view vs WPF code view

查看:108
本文介绍了VB代码视图与WPF代码视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体和WPF窗体(Visual Basic 2008)中都创建了一个相同的方案,但是其中只有一个有问题. WPF表单.全部围绕2个文本框和1个标签.这是非常简单的代码.我需要使用WPF表单,这样我才能获得不受显示器限制的表单高度.

I created an identical scenario in both a windows form and a WPF form (Visual Basic 2008), but only one of them had a problem; the WPF form. It is all centered around 2 Textboxes and one Label. Here is the very straight forward code. I need to use the WPF form so I can get a form height that is not Limited by my monitor.

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
  TextBox13.Text = TextBox17.Text
End Sub


如果您想知道(我不会怪您),我确实在WPF表单的代码视图中输入了代码.如果您知道要在XAML中输入什么代码来完成这项工作,那么我很乐意看到.

在Windows窗体中,TextBox13从TextBox17复制的Label1单击事件在Windows窗体中工作正常,但是在WPF窗体中出现错误.
此错误:

Handles子句需要在包含类型或其中一种基本类型中定义的WithEvents变量.

我还注意到,我必须在WPF中声明两个文本框,但没有在Windows窗体中声明.
我猜想该补救措施仅超出我的经验水平.


In case you are wondering (and I wouldn’t blame you) I did enter the code in the code view of the WPF form. If you know what code to enter in XAML to do the job, I would love to see that.

The Label1 click event where TextBox13 copies from TextBox17 worked fine in the windows form, but I got an error in the WPF form.
This error:

Handles clause requires a WithEvents variable defined in the containing type or one of it’s base types.

I also noticed that I had to declare the two text boxes in WPF, but did not in the windows form.
I guess the remedy is just a little beyond my experience level.

推荐答案

我不确定您是如何得到错误的. WPF标签控件没有单击事件(实际上Winforms不具有单击事件).您应该得到一个错误消息,说明Label1没有要处理的click事件或类似事件.

我的建议是,如果您需要在WPF中创建表单,而不是从Winforms中执行复制和粘贴处理程序,则它是一个非常不同的模型.您还应该研究数据绑定,它将为您节省很多 代码.

对于此问题,您还应该使控件成为按钮(单击是逻辑上的:-),但应将其样式设置为标签.尽管在最后一点上,您必须考虑用户体验.可以单击标签并不明显,因此您可能会使表单变得难以使用,从而使用户难以使用.

希望对您有帮助
I''m not sure how you are getting the error you are getting. The WPF label control doesn''t have a click event (in fact it is illogical that the Winforms one does). You should get an error saying Label1 doesn''t have a click event to handle or similar.

My advice is, if you need to create the form in WPF, not do the copy and paste handler from Winforms it is a very different model. You should also look into databinding, it will save you a lot of code.

As for this problem, you should also make the control a button (which it is logical to click :-)) but style it like a label. Though on this final point, you have to take into consideration the user experience. It isn''t obvious that a label can be clicked, so you might make the form harder for the user to use than necessary.

Hope this helps


这篇关于VB代码视图与WPF代码视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆