1

我有一个允许您绘制活动图的应用程序,我需要从该图中生成一个算法。

我的问题是如何在拖放后获取文本框的值?

这是我在按钮中编写的代码:

private void generat_algo(object sender, ExecutedRoutedEventArgs e)
    {
        {
           IEnumerable<DesignerItem> designerItems = this.Children.OfType<DesignerItem>();
           IEnumerable<Connection> connections = this.Children.OfType<Connection>();
4

1 回答 1

0

If you only have one textbox then just access the textbox by name:

textbox1.Text

Or, if you need to support multiple textboxes then you can simply get the text when the drag/drop is complete. Just handle the Drop event and check if it is a textbox that was moved:

private void Canvas_Drop(object sender, DragEventArgs e)
{
    bool itemIsTextbox = (e.Data.GetDataPresent(typeof(TextBox)) == true);

    //get the textbox then get hte text out of it
    if (itemIsTextbox)
        string text = (TextBox)e.Data.GetData(typeof(TextBox)).Text;
}
于 2012-11-13T14:37:55.743 回答