Tap release event to do something when user release a button - xaml

I need to do something when the user press and hold a button, and then do something when the user release that pressed button. Is there a tap release event ?

MouseLeftButtonDown and MouseLeftButtonUp.
For more information on relation between tap and mouse events see: msdn: Quickstart: Touch input for Windows Phone. It lists MouseLeftButtonDown, MouseLeftButtonUp, MouseLeave, MouseMove, MouseEnter as the mouse events used by Windows Phone to react to touch.
Button does not Raise MouseLeftButtonDown or -Up, so for this to work you can place a Control that does, e.g. Grid
<Grid>
<Button />
<Grid
MouseLeftButtonDown="HandleMouseLeftButtonDown"
MouseLeftButtonUp="HandleMouseLeftButtonUp"
Background="Transparent"/>
</Grid>

Related

How to prevent Esc key from light dismissing a popup?

I have a Popup which needs to be light dismissed when user taps an element outside the popup. By default, pressing the Esc key also triggers LightDismiss, which I would like to prevent. Instead, I'd like to handle this KeyDown event explicitly.
Handling the Tapped event in the page's root to check if user's tapped outside the popup is one solution, but since every tap in my app will go through this, I'd prefer not to take this approach.
Some pseudo-code:
<Page>
<Grid>
<Popup
x:Name="FooTip"
Opened="FooTip_Opened"
Closed="FooTip_Closed"
IsLightDismissEnabled="True"
ShouldConstrainToRootBounds="True">
<!-- Popup content here -->
</Popup>
</Grid>
</Page>
TLDR: FooTip should not get light dismissed when Esc key is pressed.
FooTip should not get light dismissed when Esc key is pressed.
You could handle the PreviewKeyDown event for the Page like this:
private void OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Escape
&& FooTip.IsOpen)
{
e.Handled = true;
}
}

how to disable auto tab after pressing enter and losing focus of textbox

I have an Event Handler for a keyDownEvent in a TextBox. Now when I press Enter this Event Handler changes the Visibility to Collapsed and the TextBox hides. the Problem with it is that this obviously unfocus the TextBox and foucus sth. else in my App. How can I disable this autofocus of another element and focus nothing?
I have tried the following but i am really screwed.
if (e->Key == Windows::System::VirtualKey::Enter) {
this->mode = ITEM_MODE::SELECT; // will Change Visibility to Collapsed
FocusManager::TryMoveFocus(FocusNavigationDirection::None);
e->Handled = true;
}
Thanks for your help! <3
how to disable auto tab after pressing enter and losing focus of textbox
Derive from official document,
UseSystemFocusVisuals used to get or set a value that indicates whether the control uses focus visuals that are drawn by the system or those defined in the control template.
You could set control UseSystemFocusVisuals property as False. Then next control will not be focused by system.
<StackPanel Orientation="Vertical" Name="RootLayout" IsTapEnabled="False" >
<TextBox HorizontalAlignment="Stretch" Height="44" KeyDown="TextBox_KeyDown" />
<Button Content="FouceElement" UseSystemFocusVisuals="False"/>
<Button Content="NextBtn" UseSystemFocusVisuals="False"/>
</StackPanel>
In case you just don't want the auto-focused item to have focus indicator shown, you can change the Focus type to FocusState.Pointer.
Example (C#):
object focusedElement = FocusManager.GetFocusedElement();
((Control)focusedElement).Focus(FocusState.Pointer); // This will hide focus indicator

Press event preventing pan responder - React Native

I have an animated component(Animation) which its sole purpose is to swipe its content left and right horizontally.
Inside my Animation component I have a few buttons as its children. See below:
<Animation onSwipeRight={backMonth} onSwipeLeft={advanceMonth}>
<Button onPress={select}/>
<Button onPress={select}/>
<Button onPress={select}/>
<Button onPress={select}/>
</Animation>
I realized that the button press takes preference, preventing the swipe animation to happen.
What I wanted to happen, is that on a longPress the pan responder would always swipe the buttons(even when I press one of them while trying to swipe), otherwise on quick button presses, each button individually would call its selection callback after I release my finger.

How to make button bound to ICommand enable/disable when text changes, as opposed to losing focus of TextBox

I have a Windows Store XAML app with a "Save" button, which points to an ICommand property in my ViewModel.
<Button Content="Save"
Command="{Binding DataContext.SaveNewNote, ElementName=grid, Mode=OneWay}"
CommandParameter="{Binding DataContext.CurrentItem, ElementName=grid}" />
on the propertychanged event of my Note model, that fires the CanExecutedChanged event - every time (every keystroke). However, this button will only enable/disable once I leave focus of one of the related textboxes.
In other words, there is a "Name" textbox. If String.IsNullOrWhiteSpace(Name.Text), then CanExecute is set to false. This seems to execute with every keystroke.
I would expect to see this bound Save button enable and disable with each keystroke. HOWEVER, instead, I see the button enable/disable only when I tab out of the textbox.
How can I get this bound button to respect the CanExecuteChanged event on every keystroke, instead of when the texbox loses focus?
The comments by #will and #patrick on the original post both had the correct answer. To do this, you must set the "UpdateSourceTrigger" to "PropertyChanged" and that gives the intended results.
<TextBox Grid.Row="1" PlaceholderText="Enter a short description here"
Text="{Binding NoteAbstract, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
</TextBox>

Is there a checkbox-like button in WinRT-XAML

Is there a checkbox-like button in WinRT-XAML?
What I mean, is there a button with an IsPressed (or equiv) property that will remain pressed after the user taps it? Then "unselects" after the user taps it again?
ToggleSwitch is what you're looking for
Yes, its called "Toggle Button" or "Toggle Switch".
For more details refer MSDN : WinRT control List