【问题标题】:Textbox tapped event don't fire on windows 8 for mouse click文本框点击事件不会在 Windows 8 上触发鼠标点击
【发布时间】:2013-10-14 08:43:15
【问题描述】:

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

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

【问题讨论】:

  • 你想实现什么行为?也许 GotFocus 活动对你有用。
  • @Anubis1233 感谢根据我需要工作的伙伴,如果您将其作为答案,我会为您选择它。实际上很明显,现在我认为 bout 它! :)

标签: c# visual-studio-2012 windows-8 windows-store-apps mouseclick-event


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    txtcontent.AddHandler(TappedEvent, new TappedEventHandler(txtcontent_Tapped), true);
    
      void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("Tested!!");
            }
    

    这里是相同的完整代码sn-p。

    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!!");
            }
    

    希望对你有帮助。

    谢谢。

    【讨论】:

      【解决方案3】:
          private void txtbox_GotFocus(object sender, RoutedEventArgs e)
          {
              txtbox.Text = ""; // da e34n el txtbox yb2a empty when clicked ;)
          }
      

      试试这个;)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-18
        • 1970-01-01
        • 2020-12-27
        • 2019-03-03
        相关资源
        最近更新 更多