I've added some UIelements (buttons) programatically to my application interface and i'd like to handle tap events.
I would have done it in my xaml file with
<Button Tap="onTap"/>
How could I do it in C# ? I don't know how i shall use Button.Tap=....
I Have prepared the handler like that :
private void onTouch(object sender, System.Windows.Input.GestureEventArgs e)
{
//Cool stuff here
}
Thank you in advance
You can use += to attach event handler in C# :
MyButton.Tap += onTouch;
Related
I want to open a form, make a screenshot and close it.
So I tried the Shown Event, but this fired before everything is painted.
Since Shown is the last event fired (according to MSDN), what can I do?
I think just delaying isn't such a good idea in an event driven environment.
Any advice? Thx in adv.
<
{
InitializeComponent();
UpdateData();
this.Shown += new System.EventHandler(this.PrintForm_Shown);
this.ShowDialog();
}
private void PrintForm_Shown(object sender, EventArgs e)
{
DoPrintForm();
Close();
}
>
I added to my DataPicker unfocused event. And in this event I would like to check if Done button was clicked.
private void DatePicker_Unfocused(object sender, FocusEventArgs e)
{
}
Or other option.
Is it possible to add listener to button Done, and if was clicked then fired some method?
How can I do it?
Thank you.
Every UI control which receives input always has some event handlers which you can listen to.
In your case the DatePicker has an Event Handler which fires when the Date property changes.
Here is the documentation:
DatePicker Event Handler - Xamarin Documentation
The implementation of this handler is simple:
DatePicker datePicker;
DateTime newDate;
DateTime oldDate;
public YourPage()
{
datePicker.DateSelected += Date_DateSelected;
}
void Date_DateSelected(object sender, DateChangedEventArgs e)
{
newDate = e.NewDate;
oldDate = e.OldDate;
}
Always read the documentation first, as that's the best way to learn how to use a specific control.
How to enable
PhoneApplicationPage_BackKeyPress
event when set textbox.Focus() on textbox_LostFocus event in windows phone 8.
I want to show keyboard when i add some item into listbox from textbox. Listbox gets update but my keyboard always gets hide on button click.
I want to make it open all the time till i press back key.
Thanks,
Nishant
you can get BackKeyPress Event by :
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
}
You can write textbox.Focus() at the end of button click when all work is done
try this :
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
ListboxName.Items.Add(TextBoxName.Text);
TextBoxName.Text = "";
TextBoxName.Focus();
}
I have implemented. Its working...
I am using a pivot page in my wp7 application. The PivotItems are added programatically. I need to get events of all the gestures. How can I get them?
And, how to know the direction of flick gesture? After swiping how to get details of the current item.
I was trying this : WP7: Questions regarding Touch Gestures. But could not add
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick" />
</toolkit:GestureService.GestureListener>
when I am trying to add this, an error occurs.
How can I get gesture events?
There is additional support for detecting touch in the XNA library. Trying adding the Microsoft.Xna.Framework.Input.Touch reference to your project
Include the following using statement:
using Microsoft.Xna.Framework.Input.Touch;
Subscribe to the required events in your constructor as follows:
TouchPanel.EnabledGestures = GestureType.Tap | GestureType.Flick;
On your control create an event for Manipulation Completed as follows:
ManipulationCompleted="Object_ManipulationCompleted"
You could add code to the that event method to track the type of events that have been completed with the following code:
private void Object_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
while (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
if (gesture.GestureType == GestureType.Tap)
{
//Do something
}
if (gesture.GestureType == GestureType.Flick)
{
//The delta contains the direction of the flick (negative/positive)
//gesture.Delta.Y;
//gesture.Delta.X;
}
}
}
Hope this Helps
In normal version of silverlight you can create an event handler by registering it by EventManager. Windows Phone 7 hasn't got that class.
My question is: How to create an event, which will be handled by the parent panels.
My scenario: I've created a custom class with some textbox in it. Foreach I've added my custom behavior, which raises when textblock is clicked. Behavior works like: "When this Textblock in custom control is clicked, please raise a custom event with my custom args (i want to pass them to the Custom Control itself (for example to specify to which VisualState change it)."
Can you help me how to handle my problem?
Could you provide sample code of what you are trying to do? it seems you want to create an event for when the TextBlock is clicked.
Add an event handler to the textblock:
public Event EventHandler<RoutedEventsArgs> TextClicked;
// Fire the event
private void OnTextClicked(object sender, RoutedEventArgs e)
{
if (TextClicked != null)
{
TextClicked(sender, e);
}
}
TextBlock.Click =+ OnTextBlockClicked;
private void OnTextBlockClicked(object sender, RoutedEventArgs e)
{
// Raise event
OnTextClicked(sender, e);
}
Something along those lines I think.