Textbox tapped event don't fire on windows 8 for mouse click
-
30-06-2022 - |
Question
I have the following code that builds me a text box. The application requires me to make all my controls generic, as that is the way our api is sending it to us.
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;
Now the problem is when I click on the textbox it does not fire the tapped event. I understand that the mouse click will fire the tapped event for a store app?
Here is 1st part of the tapped event, but I never reach it.
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]);
}
Can anyone please tell me what i must do, or what i am doing wrong here?
Solution
OTHER TIPS
You can use the following code to associated Tapped Event to the Textbox using AddHandler method.
txtcontent.AddHandler(TappedEvent, new TappedEventHandler(txtcontent_Tapped), true);
void txtcontent_Tapped(object sender, TappedRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Tested!!");
}
Here is completed code snippet for the same.
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!!");
}
Hope it helps.
Thank you.
private void txtbox_GotFocus(object sender, RoutedEventArgs e)
{
txtbox.Text = ""; // da e34n el txtbox yb2a empty when clicked ;)
}
try this ;)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow