Where Can I Find Key Events in LightSwitch? - events

I'm working on a project in Lightswitch and I'm trying to handle the keyup event on specific screen
I couldn't find it, where can I find those events (such us KeyUp KeyDown LostFocus ext. )
and if they are not supported what should I do to handle a situation like that?

I guess you are referring to controls and not the actual screen. So, for example, to handle keyboard events on a textbox, one way of achieving it is like in this example, where I have an "Address1" textbox and I want to change its text whenever the user types a certain letter:
1 - On the Activated event of the screen, you can get to the required textbox:
partial void CustomersListDetail_Activated()
{
this.FindControl("Address1").ControlAvailable += AddressTextBoxAvailable;
}
2 - On the Available event handler, you can connect with the required event (you can have KeyUp, KeyDown, LostFocus and others):
private void AddressTextBoxAvailable(object sender, ControlAvailableEventArgs e)
{
((System.Windows.Controls.TextBox) e.Control).KeyUp += AddressTextBoxKeyUp;
}
3 - On the KeyUp event handler, you can do your manipulation:
private void AddressTextBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.A)
{
((System.Windows.Controls.TextBox) sender).Text = "You typed A";
}
}

Related

Xamarin DataPicker how to handle done button click event

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

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...

Make a difference between a tab event and a flick event on listbox

I have a listbox which contains a list of images; I don't know how to differentiate betwwen a Flick event and a Tap event, to make a zoom on the chosen image?
There is a Tap event on all elements (in Mango). Tap event don't raised when user scrolls a list.
Also, you can place an image inside a retemplated Button (leave only content holder). Then you get for free Click event and Tilt Effect as well
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 list box create an event for Manipulation Completed as follows:
ManipulationCompleted="ListBoxDays_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 ListBoxDays_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
while (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
if (gesture.GestureType == GestureType.Tap)
{
//Do something
}
if (gesture.GestureType == GestureType.Flick)
{
//Do something else
}
}
}
Hope this Helps

RoutedEvents in WP7 Custom Control

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.

Windows phone 7 Handling backspace KeyDown event

I have a textbox in XAML:
<TextBox Text="blah"
Name="blah"
LostFocus="blah_OnLostFocus"
KeyDown="blah_OnKeyDown"/>
.cs file has the following event declared:
private void blah_OnKeyDown(object sender, KeyEventArgs e)
{
TextBox t = sender as TextBox;
int i = 0;
if(e.Key == Key.Delete)
i = 1;
}
When I press the backspace key on the emulator's keyboard, the event is ignored. If I press any other button, it is triggered. Also, when I use the same event body for the KeyUp event, backspace key triggers it.
How do I track when the backspace key was pressed for KeyDown event? Why is pressing the backspace key does not trigger the KeyDown event?
Thank you.
The backspace button is handled internally by the textbox control. The control will take the backspace event and remove a letter and won't bubble up the event to your event. This is by design. You'll notice that if there are no letters in the textbox, then the event is bubbled up. In order to get around this, you can use AddHandler to handle the event. Try doing this:
//Handle the mainpage loaded event and add the handler to the textbox
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
textBox1.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(blah_KeyDown), true);
}
Then change your Key_Down event handler to this:
private void blah_OnKeyDown(object sender, KeyEventArgs e)
{
TextBox t = sender as TextBox;
int i = 0;
if(e.Key == Key.Back)
i = 1;
}
That should have the textbox internally handle the event, but also call your OnKeyDown event.
To detect backspace, you need to use Key.Back rather than Key.Delete
See Key enumeration at http://msdn.microsoft.com/en-us/library/system.windows.input.key(v=VS.95).aspx

Resources