none
TextBox Tapped event not being called in Windows 8 RC

    Question

  • After a long time making my Consumer Preview App RUN in RC, I am now trying to figure why my "Tapped" event on a TextBox is not being called...Did somebody had the same problem and managed to fix it? Tried PointerPressed, but  it's not working as well...

    Here's the Xaml:

    <TextBox IsReadOnly="True" Name="txtImgCarro" IsTapEnabled="True" Tapped="txtImgCarro_Tapped" PointerPressed="txtImgCarro_PointerPressed"/>

    And the behind code:

    private async void _pickPhoto()
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.List;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".png");
                StorageFile file = await openPicker.PickSingleFileAsync();
                if (file != null)
                {
                    txtImgCarro.Text = System.IO.Path.GetFileName(file.Path);
                    this.imagemCarro = file;
                }
                else
                {
                    // Could not find file
                }
            }
    
            private void txtImgCarro_Tapped(object sender, TappedRoutedEventArgs e)
            {
                this._pickPhoto();
            }
    
            private void txtImgCarro_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                this._pickPhoto();
            }

    Thx in advance ;)

    Wednesday, June 13, 2012 9:50 PM

Answers

  • So what's happening is that the TextBox is eating those messages before you get them.  One of the disadvantages of WinRT - WPF had a beautiful system for dealing with this situation where events filtered down and then up, so you could always pick up the sort of things.  Anyways, to work around that add the following code into your constructor:

    txtImgCarro.AddHandler(TappedEvent, new TappedEventHandler(txtImgCarro_Tapped), true);

    This will get you the event, even if it has been processed ( that's what the true is for )

    ...Stefan

    • Marked as answer by ducke1942 Thursday, June 14, 2012 1:49 PM
    Thursday, June 14, 2012 2:19 AM

All replies

  • So what's happening is that the TextBox is eating those messages before you get them.  One of the disadvantages of WinRT - WPF had a beautiful system for dealing with this situation where events filtered down and then up, so you could always pick up the sort of things.  Anyways, to work around that add the following code into your constructor:

    txtImgCarro.AddHandler(TappedEvent, new TappedEventHandler(txtImgCarro_Tapped), true);

    This will get you the event, even if it has been processed ( that's what the true is for )

    ...Stefan

    • Marked as answer by ducke1942 Thursday, June 14, 2012 1:49 PM
    Thursday, June 14, 2012 2:19 AM
  • That worked perfectly! Thanks!
    Thursday, June 14, 2012 1:50 PM