【发布时间】:2014-04-14 20:14:53
【问题描述】:
大家好,我已经创建了一些文本框和按钮,以便在运行时与它们一起使用。
按钮的代码是:
Dim updateButton As New Button
updateButton.Name = "button_" & ticketTheRowNum & "_" & ticketRowNum
updateButton.Content = "UPDATE!"
updateButton.Height = 26
Canvas.SetTop(updateButton, 24 * ticketTheRowNum)
Canvas.SetLeft(updateButton, 330 + lblNotes.Width)
updateButton.Width = lblNotes.Width / 2 - 10
updateButton.Background = New SolidColorBrush(Colors.Green)
Grid.SetRow(updateButton, 0)
Grid.SetColumn(updateButton, 0)
Grid.SetZIndex(updateButton, 2500)
cavTicket.Children.Add(updateButton)
文本框的代码是这样的:
Dim txtBlock As New TextBox
txtBlock.Name = "txt_" & ticketTheRowNum & "_" & ticketRowNum
txtBlock.Text = theHeader
txtBlock.TextWrapping = TextWrapping.Wrap
txtBlock.Width = lblNotes.Width - 5
txtBlock.BorderThickness = New Thickness(0)
txtBlock.TextAlignment = TextAlignment.Left
txtBlock.VerticalScrollBarVisibility = ScrollBarVisibility.Auto
tmpExpander.Content = txtBlock
现在按钮和文本框在 WPF 上显示得很好,但我不确定如何连接按钮以使其知道文本框中的内容并保存其内容。目前,由于我在运行时创建这些,因此如果它在运行之前已经在表单上,我将无法访问(我只需调用按钮单击事件,然后在其中调用文本框内容并保存)。
【问题讨论】:
-
这通常是您使用 XAML 的目的;这就是 WPF 的用途,所以你不要做这样的事情。
标签: wpf vb.net wpf-controls textblock