I have a textbox in scrollviewer, I want to hide the virtual keyboard when I scroll.
the keyboard is hidden when the scrollviewer is tapped but not when I scroll.
I tried to change focus to another element in the viewchanged event of the scrollviewer but not working.
When the textbox that showed the virtual keyboard has property IsEnabled set to false, the virtual keyboard disappears. We can immediately set is to true after that and the virtual keyboard will remain hidden. Here is how to do it:
searchTextBox.KeyDown += (s, a) => {
if (a.Key == VirtualKey.Enter) {
searchTextBox.IsEnabled = false;
searchTextBox.IsEnabled = true;
}
};
Related
I have a listview which i reload when i click on an item. I want to remember the scroll position so I use the following code:
private double scrollPosition;
public void SaveListPosition()
{
scrollPosition = scrollViewer.VerticalOffset;
}
public void ScrollToSavedPosition()
{
scrollViewer.ChangeView(0, scrollPosition, null, false);
}
Its working fine, but it shows the scrolling. After I change the ChangeView method's disableAnimation parameter to true it doesn't show scrolling as expected, but it completely messes up list positions and doesn't scroll to the element that I clicked.
So questions are:
1) is this a bug in winrt?
2) can I override the ChangeView's animation so it will instantly scroll exactly like supplying true for the disableAnimation parameter?
3) Any other solution?
In WP8, how to hide the soft keyboard when the listbox is scrolled?
Is there an event to detect when the listbox is scrolled?
So I duplicated your problem in a Windows Phone 8 application.
I tested this solution and it does in fact work.
What you want to do is target the ListBox.ManipulationStarted event
Inside this event just simply do this.Focus();
This will cause the soft keyboard to retreat
Your final product might look like this
public page2()
{
InitializeComponent();
for (int x = 0; x < 100; x++)
{
lb.Items.Add(x);
}
lb.ManipulationStarted += lb_ManipulationStarted;
}
void lb_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
this.Focus();
}
So my round about way of answering your question is no, there is no scroll event for the listbox. Anything you do will be a hack similar to this but it DOES work.
I have a table (just drawn onto the stage) which has some values in it. You should be able to click on the different boxes in the table, and hide or show the value in that box.
I did this by having a layer on top of the layer with the table that has white buttons (same color as background) on it. So you should be able to click on the button, make it invisible to show the value, then click again to hide the value.
import flash.events.MouseEvent;
//these are each of the instances of the white buttons.
var visibleValues:Array=new Array(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p);
for(var t:int=0; t<visibleValues.length; t++){
visiblesValues[t].addEventListener(MouseEvent.CLICK, showValue);
}
function showValue(evt:Event):void{
if (evt.target.visible){
evt.target.visible=false;
}
else{
evt.target.visible=true;
}
}
Clicking on the button when it is visible will make it invisible (showing the number underneath), however when I try to click on it again the button does not reappear.
Why is this? Also out of curiosity is there a simpler way to do this? It seems odd to have to assign the event listener to each instance, when they are all instances of the same thing.
Thanks very much!
For your first problem try setting the alpha to 0.1 instead of visible to false. When you set visible to false you are also disabling user interaction.
Click events should bubble so you can add the listener once to the parent container then use something like the event.currentTarget to get access to the button actually clicked. Where this becomes a little harder is when the label or skin parts of the button are assigned to the currentTarget.
To get around that you can either set mouseChildren to false on each button or in the event handler keep calling .parent until you hit a button or the parent container.
Note that when you listen higher you will also get clicks on the parent so you will need to handle that case in the handler.
function showValue(evt:Event):void {
// Detect which button was clicked
var target:DisplayObject = evt.currentTarget as DisplayObject;
while(target) {
if (target is Button) {
break;
}
// container clicked so exit
if (target == container) {
return;
}
target = target.parent;
}
// No button was clicked so exit
if (!target) {
return;
}
// If we are solid then hide
if (target.alpha == 1){
target.alpha = 0.1;
} else{
target.alpha = 1;
}
}
I have a PhoneApplicationPage with some grids, images and a few buttons. If I tap outside my buttons, anywhere in the page (on an image, grid or whatever), I want to open a new page.
How can I detect a tap/click anywhere on the page?
I see at least two ways to do that:
Listen to the MouseLeftButtonUp event on your PhoneApplicationPage. It should be triggered by images and labels but not by buttons
Listen to the Tap event on your PhoneApplicationPage. However, this event will be triggered even when the user tap on a button. To prevent this, you can retrieve the list of controls at the tap coordinates in the event handler, and open the new page only if there's no button:
private void PhoneApplicationPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var element = (UIElement)sender;
var controls = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(element), element);
if(controls.OfType<Button>().Any())
{
return;
}
// Open the new page
}
I am creating a menu this way :
myMenu = Menu.createMenu( null, myMenuXMLListCollection, false );
and then showing it with :
myMenu.popup( 10, 10 );
but the menu doesn't disappear automatically when i click somewhere outside the menu.
Is there some way to make the menu disappear automatically when i click outside it ?
Listen for the SandBoxMouseEvent.MOUSE_UP_SOMEWHERE on the sandbox root. You can get the Sandbox root using SystemManager.getSandboxRoot
So, add your event listener, something like this:
systemManager.getSandBoxRoot.addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, myMouseUpHandler);
And then in your event handler, just check to see if the target is the menu and if not hide the menu:
protected function myMouseUpHandler(event:SandboxMouseEvent):void{
if(event.target != myMenuInstance){
myMenuInstance.visible = false;
// or whatever other action you wish to take to hide the menu.
}
}
This is the general approach that the Flex ComboBox uses to hide the drop down menu on mouse click.