C# 文本框点击事件don';t在windows 8上启动鼠标单击

C# 文本框点击事件don';t在windows 8上启动鼠标单击,c#,visual-studio-2012,windows-8,windows-store-apps,mouseclick-event,C#,Visual Studio 2012,Windows 8,Windows Store Apps,Mouseclick Event,下面的代码为我构建了一个文本框。 应用程序要求我将所有控件设置为通用, 因为这就是api发送给我们的方式 TextBox txtcontent = new TextBox(); txtcontent.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; txtcontent.SetValue(Grid.ColumnProperty, 1); txtcontent.SetValue(Grid.RowProperty,

下面的代码为我构建了一个文本框。 应用程序要求我将所有控件设置为通用, 因为这就是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]);
}

有人能告诉我我必须做什么,或者我做错了什么吗?

您想使用控件的事件。

您想使用控件的事件。

您可以使用以下代码使用AddHandler方法将点击事件关联到文本框

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!!");
        }
希望能有帮助


谢谢。

您可以使用以下代码使用AddHandler方法将点击事件关联到文本框

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

  void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Tested!!");
        }
    private void txtbox_GotFocus(object sender, RoutedEventArgs e)
    {
        txtbox.Text = ""; // da e34n el txtbox yb2a empty when clicked ;)
    }
下面是相同的完整代码段

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!!");
        }
希望能有帮助

多谢各位

    private void txtbox_GotFocus(object sender, RoutedEventArgs e)
    {
        txtbox.Text = ""; // da e34n el txtbox yb2a empty when clicked ;)
    }
试试这个;)


试试这个;)

您希望实现什么行为?也许GotFocus活动对你有用。@Anubis1233谢谢你,伙计,这是我所需要的,如果你回答了,我会为你选择。其实现在很明显,我觉得鲍特吧!:)您希望实现什么行为?也许GotFocus活动对你有用。@Anubis1233谢谢你,伙计,这是我所需要的,如果你回答了,我会为你选择。其实现在很明显,我觉得鲍特吧!:)