I've been scouring the web looking for examples on how to handle flick gestures on Windows Phone 7 in the ViewModel using MVVM Light.
I've found some good resources on handling commands from button clicks and such, but I can't seem to find anything on how to handle gestures. Anyone know if this is possible? If so, are there any good resources or can you provide a quick example how this could be done?
If not, I guess I'll just have to break down and put code in the code-behind. Ugh, makes me sick thinking of it. ;)
You can use the GestureListenerEx from Wp7Tools.
Add Wp7Tools to your project:
PM> install-package wp7tools
In your xaml:
<Rectangle Fill="Red" Width="100" Height="100">
<toolkit:GestureService.GestureListener>
<wp7:GestureListenerEx
OnTapAction="Tap"
OnDragStartedAction="DragStart"
OnDragCompletedAction="DragEnd"
/>
</toolkit:GestureService.GestureListener>
</Rectangle>
And in your ViewModel:
public void Tap(GestureEventArgs e) {
//Do something
}
public void DragStart(DragStartedGestureEventArgs e) {
Debug.WriteLine(e.Direction);
}
public void DragEnd(DragCompletedGestureEventArgs e) {
Debug.WriteLine(e.Direction);
}
That's it. No code-behind, no commands, just point the method you want to be executed :)
How about making the control set you want to apply gestures to a user control?
Or even wrap a user control around the gesture listener then surface properties using dependency properties so you can bind to them
Related
We have developed an application in Xamarin Forms. In Android application when the user uses the app in a low-network for about 90 seconds we are getting app not responding(ANR) Popup. Here my question is, is there any way to avoid this ANR popup in my application? In other words, is there any way to force the android system to wait for longer time?
In our Application when the user launching the application we are doing multiple tasks on threads which are majorly running on the secondary threads like:
Initialize Google Map & Creating Pins & Polyline Drawing
Firebase Listener Register
REST API calls
Loading List Items
So, before the device completes the above the list of task, if the users keep on touching the screen, then this causes multiple events to be queued in the main thread due to which we are getting ANR(App Not Responding Popup).
Here, we intend to disable the touch event until we complete the main thread in the existing task.
You can use the below logic to restrict touches to the content of the page below the activity indicator to resolve your issue.
However, the touches for the Grid below will still be listened to by the Android system and it will be processed. Here you can only restrict the interaction to your application views. However, the touch listened by the Android system for the Grid, ContentView, or ActivityIndicator in the below code can never be ignored.
Ideally, no user will try to touch more number of times after realizing there is no interaction when the loader is loading. So I guess you can safely ignore this case considering the general user thought process.
<Grid Grid.RowSpan="2"
InputTransparent="{Binding IsPageInteractable}"
IsVisible="{Binding IsPageBusy}">
<ContentView Opacity="0.2"
BackgroundColor="#4B4B4B"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
<ActivityIndicator IsRunning="{Binding IsPageBusy}"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" />
</Grid>
public bool IsPageInteractable
{
get { return _isPageInteractable; }
set { _isPageInteractable = value; }
}
public bool IsPageBusy
{
get { return _isPageBusy; }
set
{
_isPageBusy = value;
this.IsPageInteractable = !value;
}
}
I got a small question for you. I am currently developing an application, based on Xamarin.Forms, and, on a ContentPage, i would like to always (yes i mean always always) show the keyboard. There is a textfield and some buttons or list, and when I click/tap on it, keayboard is hidden (and that is the standard behavior).
But here, I do not want if possible, to set the focus on the field for every action possible on the page. And even if I do that, we can see that the keyboard disappear and is shown back just after (trust me, me eyes are crying when it blink :)).
So, is it possible to set somewhere that we want to always show/display the keyboard ?
thanks a lot
Actually , it is not a good decision to keep the keyboard on the ContentPage , it will block other event like scroll and tap .
If you do want to implement it. You could define a default entry and set it onfocus when you finish editing other enrties .
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<Entry x:Name="defaultEntry" HeightRequest="0.1" WidthRequest="0.1" Unfocused="Entry_Unfocused" />
<Entry HeightRequest="100" WidthRequest="40" Unfocused="Entry_Unfocused" />
</StackLayout>
bool IsNeedShowKeyBoard=true ;
public MainPage()
{
InitializeComponent();
}
private void Entry_Unfocused(object sender, FocusEventArgs e)
{
if(IsNeedShowKeyBoard)
{
defaultEntry.Focus();
}
}
Change the property IsNeedShowKeyBoard to false when start to scroll or you want to edit other entry .
In fact, I will develop my own custom keyboard. With that solution, I will be able to let it be shown every time.
I've got a ListBox (dynamically populated via code):
(i can't insert the code, bah)
I need, with a button, to move this listbox vertically. The listbox have a fixed height, and also the items.
Can someone help me?
Per MSDN, it looks like this is a viable answer for you?
ListBox.ScrollIntoView Method
Edit - Comment Summary of Answer: The question here was targetting scrolling itself, not to a particular object. As such, the necessary action was to attain a reference to the ListBox's ScrollViewer. From there, a call needed to be placed to the ScrollViewer's ScrollToVerticalOffset method. As the OP wanted to scroll down a certain amount from the original position, the ScrollViewer's VerticalOffset property was incorporated into the call.
This works. Set the ListBox to not scroll, then add a ScrollViewer around it. Now in your code behind you can set the ScrollViewer to whatever you want.
XAML:
<!--Disable the ListBox scroll and add a ScrollViewer so we have control over the scroll position.-->
<ScrollViewer
Name="scrlvwrListBoxMessages"
VerticalScrollBarVisibility="Auto" >
<ListBox x:Name="lstbxMessages"
ScrollViewer.VerticalScrollBarVisibility="Disabled" >
</ListBox>
</ScrollViewer>
Code:
private void ScrollToBottom()
{
//Scroll to the bottom.
Dispatcher.BeginInvoke(() =>
{
this.scrlvwrListBoxMessages.ScrollToVerticalOffset(double.MaxValue);
});
}
I have a gesture listener. I use DoubleTap to toggle a ListBox Visibility on my page.
And Flick gesture to flick images.
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
DoubleTap="GestureListener_DoubleTap"
Flick="GestureListener_Flick"/>
</toolkit:GestureService.GestureListener>
I'am trying to disable the flick gesture when the ListBox is visible.
Can anyone help here?
Thanks in advance!
G.
You could probably do this with a custom behaviour but I'm not really up to speed on them. I would just do the following in code behind:
GestureListener listener = GestureService.GetGestureListener(myControl);
listener.Flick -= GestureListener_Flick;
I found out that you can disable GestureListeners through flicking this boolean off:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.ishittestvisible(v=vs.95).aspx
Might be simpler in some scenarios, but it will of course disable likely all events tied to that object.
See my question about WP7 slider strange behavior
I use
TouchPanel.EnabledGestures = GestureType.None
to disable gesture. Remember to save previous GestureType
Hi I want to create a looping listbox so that the last item's next item is the very first item and vice versa - creating a listbox that doesn't have a top or a bottom.
I know there is a LoopingSelector in the WP7 toolkit but it doesn't quite do what I want since it fades in/out peripheral items and you have a 'selected' item that is always in the middle.
I looked at the LinkedList collection but it doesn't seem to support looping: "The LinkedList(Of T) class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state."
Does anyone know a solution for what I'm looking for or would I need to develop a hybrid of the current Listbox and the toolkit's LoopingSelector?
Many thanx!
Take a look at Petzold's article on circular lists in MSDN Magazine.
I recently have a same problem as your! I use blend 4 to handle this, making my list reset to certain position at certain time, also adding a copy of a list in front and behind of the original list.
example: my list is: 1-2-3-4-5-6,
I would make it 1-2-3-4-5-6-1-2-3-4-5-6-1-2-3-4-5-6
and it reset to original position every 20sec. For example: if user was on item 4 it would reset the position to item 4 but at the middle list.
I currently have my question asking here you can check out if anything help:
horizontal listbox that could be infinite circle scrolling
Use Scrollviewer contains listbox, put manipulationCompleted event and use ScrolltoVerticalOffset(0) to have it looping scrolling. Maybe my code would help:
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="-2,567,-1,0" x:Name="imagesScrollview"
Opacity="1" Grid.Row="1" RenderTransformOrigin="0.5,0.5"
ManipulationCompleted="imagesScrollview_ManipulationCompleted" Height="85" MouseLeftButtonDown="ScrollViewer_MouseLeftButtonDown">
<ScrollViewer.Background>
<ImageBrush ImageSource="/PhoneApp11;component/Images/top_friends_float.png" />
</ScrollViewer.Background>
<ListBox x:Name="listBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="Auto" Height="80" Background="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
and in Manipulation event:
private void imagesScrollview_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
ScrollViewer scrollviewer = sender as ScrollViewer;
if (scrollviewer.HorizontalOffset > (listBox.ActualWidth - 700))
scrollviewer.ScrollToHorizontalOffset(0);
else if (scrollviewer.HorizontalOffset < 100)
scrollviewer.ScrollToHorizontalOffset((listBox.ActualWidth - 487));
}
***Notice: I allow my scrollviewer to loop in both way.