How to get a hold events text RRS feed

  • Question

  • I have two textblock1,2 in windows phone 

    and have a hold event 

    Now when someone hold the textblock 

    i am using a sms task 

    public void hold(object sender,GetureEventArgs e)


      SmsComposeTask smsComposeTask = new SmsComposeTask();
                smsComposeTask.To = "";
                smsComposeTask.Body = textblock1.Text;


    i want to use the same event for the second textblock2 too 

    the body have to change to the event  active control 

    Solve your Problems @

    • Moved by Mike Dos Zhang Friday, May 11, 2012 7:44 AM windows phone 7 dev question (From:Visual C# General)
    Friday, May 4, 2012 8:02 PM

All replies

  • Don't know anything about phone apps so this is a guess. Is the sender the textblock that is being held? If so then you could use its text. You might have to cast it to a textblock since it's declared as an object. If that is the case then both blocks could use the same event handler.

    Regards David R
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Friday, May 4, 2012 8:13 PM
  • You can assign the same event to both objects, but you'll need to cast the sender as a textblock to get the text of the object that raised the event.

    This shows how you can have both textblocks' hold event mapped to the same peice of code:

    <TextBlock x:Name="textBlock1" Hold="textBlock1_Hold"/>
    <TextBlock x:Name="textBlock2" Hold="textBlock1_Hold"/>

    This shows how to cast the sender so that is the textblock that raised the event:

    smsComposeTask.Body = (sender as TextBlock).Text;

    In the future you should ask your Windows Phone questions here:
    It is the dedicated Windows Phone forums.

    • Edited by DavidB1000 Friday, May 4, 2012 9:05 PM
    Friday, May 4, 2012 9:05 PM
  • I am using this code but it is not working       

                <TextBlock Height="30" HorizontalAlignment="Left" Margin="168,122,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Hold="textBlock1_hold" />
                <TextBlock Height="30" HorizontalAlignment="Left" Margin="168,190,0,0" Name="textBlock2" Text="TextBlock" VerticalAlignment="Top" Hold="textBlock1_hold" />
       private void textBlock1_hold(object sender, System.Windows.Input.GestureEventArgs e)
                SmsComposeTask smsComposeTask = new SmsComposeTask();
                smsComposeTask.To = "2065550123";
                smsComposeTask.Body =(sender as TextBlock).Text;

    But it is not working 

    Need Help 

    Solve your Problems @

    Saturday, May 5, 2012 3:09 PM
  • i dunno what exactly you want , but look closely to the header of method :
    public void hold(object sender,GetureEventArgs e)

    there's an object named sender, it mean the instance of class which call the method, so if button1 call it, it's button 1, if button 2 call, its button 2, and if its any thing else, like a label call it, it's the label...

    so all you need is to cast the Type, because its object by default, like ((Button)sender), or ((Timer)sender) and get access to the inner properties... like Text in previous post...

    But there's some thing, which some time is wrong,....
    all the code didnt write by Microsoft, which mean all code are not fully standard, and also some of them are not standard at all,
    for example, when the user write the event, pass a null argument to the object, so you always receive null, but it should return this (in most case) which return the instance of class, so if you are the writer of "Hold" event and TextBlock Component (since i never see text Block in Visual Studio but textBox), send 'this' as a argument,...

    Saturday, May 5, 2012 3:23 PM
  • Please use this forum:

    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 10, 2012 10:34 AM