Is there a click behavior for a list? - windows-phone-7

I have a list view, on a panoramic control. I've also created an event for MouseLeftButtonUp however I find that when scrolling between the panorama items the MousLeftButtonUp is triggering (it makes sense why but it is unexpected from a user perspective).
Is there any way to create a click event for a list? Or add a behavior that simulates that?

Checkout the Tap gesture from the Gesture service that's part of the toolkit.
WP7 Tip of the Day: Silverlight Toolkit: Gestures
<ListBox Height="100" HorizontalAlignment="Left" Margin="12,186,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" >
<Controls:GestureService.GestureListener>
<Controls:GestureListener Tap="GestureListener_Tap">
</Controls:GestureListener>
</Controls:GestureService.GestureListener>
<ListBoxItem Content="1"/>
<ListBoxItem Content="2"/>
<ListBoxItem Content="3"/>
<ListBoxItem Content="4"/>
</ListBox>
and
public void GestureListener_Tap(object sender, GestureEventArgs e) {
System.Diagnostics.Debug.WriteLine("tap");
}

The listbox should already accept contact, so you can just fire the SelectionChanged event

Related

get listview values after click on menuItem

how to pick up the values of a listview done in WindowsPhone 8.1 then click on a MenuFlyoutItem. Example I have a listview with id, name and telephone after holding the list to appear MenuFlyoutItem want to click on a menu option and know the values of the id, name and telephone number of the line selected.
I think that this question was answered many times but I will try to give you a solution.
You can add flyout to ItemTemplate of your ListView, like this:
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Delete" />
<MenuFlyoutItem Text="Refresh" />
<MenuFlyoutItem Text="Share" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Text="{Binding Title}" Style="{ThemeResource ListViewItemTextBlockStyle}" />
</StackPanel>
</DataTemplate>
Now, MenuFlyoutItem has event named "Click" so if you are using a "code-behind" approach you can create event handlers for your click events of menuFlyoutItems in page code. I believe that event args of this event will have information about which item was clicked.
Please look at this blog note I found, it may be useful for you:
http://igrali.com/2014/04/28/show-context-menu-using-menuflyout-windows-phone-8-1/

How to receive MouseMove or ManipulationDelta events from a LongListSelector in Windows Phone 7 and/or 8

If I have a grid on a normal page I can do the following and the event handler is called numerous times.
<Grid ManipulationDelta="My_ManipulationDelta" />
If instead, I add it to a longlistselector, it's called few times and the value is usually the same each time
<phone:LongListSelector ManipulationDelta="My_ManipulationDelta" />
I've also tried adding it to the itemtemplate, which had the same results:
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<TextBlock
ManipulationDelta="TextBlock_ManipulationDelta"
Text="{Binding}" />
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
Is there a work around or another event or some part of the LongListSelector that can give me information about touch movements of the user - specifically movement along the Y-axis?
If ManipulationDelta="My_ManipulationDelta" doesn't work correct, you can try GestureListener.
<toolkit:LongListSelector>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta"/>
</toolkit:GestureService.GestureListener>
...
</toolkit:LongListSelector>
But it shows only delta between the event raises.

Getting Tap even of user control in viewmodel

In my application i am using a content control to display my user control
<ContentControl Content="{Binding LayoutControl}" Grid.Row="0" Height="700" Width="450"/>
In here the binding content is a user control with the following elements.
<Grid x:Name="LayoutRoot" Background="#6C7172">
<Border BorderBrush="White" BorderThickness="7">
<Image Source="{Binding ImagePath0}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cmd:EventToCommand Command="{Binding Path=ImageTap}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
</Border>
</Grid>
In the above code what i am tried to implement is, while tapping on the image i need to fire the corresponding event in my view model, But through this code the tap event is not firing. But when i apply the interactivity to content control the click is working. I cannot simply add tap event to content control because some other cases i need to handle tap events of more than two Image controls . Can any one help me to solve this issue.
Give a fixed height and width to you image control and then try. It will work. If there is no image in the container means, the mouse will not get a position for tapping. Try this and if you still face the same issue give me a feedback.

Can I Remove a MenuItem from ContextMenu in WP7

I'm looking for a method - if at all possible - of removing a MenuItem control from a ContextMenu in Windows Phone 7.
Here's a simplified version of my XAML:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
[ -- Content -- ]
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="view attributes" Tag="ATTRIBUTES" Click="ViewSelectedResultAttributes" />
<toolkit:MenuItem Header="view groups" Tag="GROUPS" Click="ViewSelectedResultGroups" />
<toolkit:MenuItem Header="view webpage" Tag="ONLINE" Click="ViewWebPage" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now, not all of the items in the bound collection have a website associated with them, and for those items I wish to remove the MenuItem with the tag ONLINE (i.e. the last MenuItem).
But I can't find a way of achieving this.
I've also thought of adding the ContextMenu and all the MenuItems programmatically so that I could conditionally add each MenuItem but I can't seem to find an event such as OnItemDataBound or OnDataBinding, etc.
Can anyone help me out?
UPDATE: just to be more specific, I don't want to remove a MenuItem from the ContextMenu on every bound item in the ListBox, I only want to remove a MenuItem on specific items in the ListBox when the bound object fails a condition.
Let's say my ListBox contains 3 bound items:
ListItem_1,
ListItem_2,
ListItem_3
Now, let's say that the object bound to ListItem_2 has one of its properties as NULL; In this case ListItem_2 should have one of the MenuItem controls from its ContextMenu removed, whereas ListItem_1 and ListItem_3 should still have this MenuItem.
What would be ideal is an event which allows me to capture each item as it's being bound, and which also exposes the ContextMenu. The ListBox.Items collection simply returns the same collection of objects that I assigned to be the data source, whereas a collection of, say, ListBoxItems would be more useful - does this exist?
First, give a name to your context menu to be able to retrieve it easily from the code-behind:
<toolkit:ContextMenu x:Name="ContextMenu">
From there, you can access the items using this.ContextMenu.Items. So just remove the ones you don't need anymore:
var item = this.ContextMenu.Items.OfType<MenuItem>().First(m => (string)m.Tag == "ONLINE");
this.ContextMenu.Items.Remove(item);

Binding for ListboxItems not updated

I have a Listbox with data-binding to payments of a project. When I add a new payment, the payment will be added to the list. The add-page is also used to edit the payments. The event is called, in debug-mode I can see the changed value of my payment, but the ListBoxItem is not going to be updated. At the end of the add-page an event will be called, which updates the listbox items:
GlobalNotifier.OnPaymentAdded();
The OnPaymentAdded calls a method which only notifies about the property changes:
OnNotifyPropertyChanged("Project");
The code of the listbox:
<ListBox Name="ListPayments" ItemsSource="{Binding Project.Payments}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="10,5,10,0">
<StackPanel>
<TextBlock FontSize="30" Text="{Binding Name}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Why are new items added, but existing items not updated? Any idea?
What's happening is that although the Project-object is updated, the Payments object (presumably a List) is not.
What you could try is the following:
Whenever the List-object is being manipulated (edited, items removed / added), fire the PropertyChanged-event for Projects
You can also switch the List<Project> to an ObservableCollection<Project>, which surely will fix your problem
If switching to ObservableCollection is out of the question for you, implement an override for the OnNavigatedTo() in the view that shows the list, and call the PropertyChanged-events (Project, Payments etc) from there.
Either one of these should fix your problem - it's all a matter of taste and preferences.
Sounds like your item properties are not dependency properties, or nobody fires propertychanged for them.

Resources