1

我有以下代码可以构建一个文本框。该应用程序要求我将所有控件设为通用控件,因为这是我们的 api 将其发送给我们的方式。

TextBox txtcontent = new TextBox();
txtcontent.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch;
txtcontent.SetValue(Grid.ColumnProperty, 1);
txtcontent.SetValue(Grid.RowProperty, RowCount);
txtcontent.Width = 320;
txtcontent.FontSize = 20;
txtcontent.TextWrapping = TextWrapping.Wrap;
txtcontent.Margin = new Thickness(10);
txtcontent.Foreground = App.scbAccTechGrayDark;
txtcontent.BorderBrush = App.scbAccTechGrayLight;
txtcontent.Background = App.scbAccTechGreenLight;
txtcontent.Tapped += txtcontent_Tapped;

现在的问题是,当我单击文本框时,它不会触发点击事件。我知道鼠标点击会触发商店应用程序的点击事件?

这是点击事件的第一部分,但我从未达到它。

void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
{
    TextBox txtFinder = (sender as TextBox);
    string[] myconver = (sender as TextBox).Tag.ToString().Split(',');
    int BlockIndex = Convert.ToInt16(myconver[4].ToString());
    int FieldID = Convert.ToInt16(myconver[5].ToString());
    string ColumnName = Convert.ToString(myconver[6].ToString());
    string FieldCode = Convert.ToString(myconver[7]);
    string BlockName = Convert.ToString(myconver[8]);
}

谁能告诉我我必须做什么,或者我在这里做错了什么?

4

3 回答 3

4

您想使用TextBox控件的GotFocus 事件。

于 2013-10-14T13:29:41.723 回答
3

您可以使用以下代码使用 AddHandler 方法将 Tapped Event 关联到 Textbox。

txtcontent.AddHandler(TappedEvent, new TappedEventHandler(txtcontent_Tapped), true);

  void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Tested!!");
        }

这是相同的完整代码片段。

public MainPage()
        {
            this.InitializeComponent();
            AddControl();
        }



        private void AddControl()
        {
            TextBox txtcontent = new TextBox();
            txtcontent.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch;
            txtcontent.SetValue(Grid.ColumnProperty, 1);
            txtcontent.SetValue(Grid.RowProperty, 0);
            txtcontent.Width = 150;
            txtcontent.FontSize = 20;
            txtcontent.TextWrapping = TextWrapping.Wrap;
            txtcontent.Margin = new Thickness(10);
            txtcontent.AddHandler(TappedEvent, new TappedEventHandler(txtcontent_Tapped), true);
            //txtcontent.Foreground = new Solid
            //txtcontent.BorderBrush = App.scbAccTechGrayLight;
            //txtcontent.Background = App.scbAccTechGreenLight;
            this.LayoutRoot.Children.Add(txtcontent);
        }


        void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Tested by WmDev!!");
        }

希望能帮助到你。

谢谢你。

于 2013-10-14T14:06:43.230 回答
0
    private void txtbox_GotFocus(object sender, RoutedEventArgs e)
    {
        txtbox.Text = ""; // da e34n el txtbox yb2a empty when clicked ;)
    }

试试这个 ;)

于 2014-08-30T11:53:23.667 回答