Silverlight 2.0 RC Drag and drop ordering of a ListBox - silverlight-2-rc0

I am trying to give a ListBox drag and drop ordering functionality and I have hit a wall. I got it to work when I specify the list box items in xaml but it does not work when I bind to a list it no longer works because the items are no longer of a listboxitem type.
I found this code http://blog.dobaginski.com/josh/?p=52 that allows me to get the underlying ListBoxItem but I can't get the mouse move event to fire.
I have went through other tutorials but have not been able to find one that deals with a ListBox. Has anyone done this with a ListBox.
The events I am using are SelectedChange, MouseMove, and LeftMouseButtonUp (I think that name is right). I am not using LeftMouseButtonDown because I couldn't get it to fire.

As far as i know you cannot get at the listbox item container when using data binding. YOu could in Beta 1.
You also cannot set a mouse event handler in the style, you must use a data template, just so you know.
You will likely have to use the mouse move event from a parent element, probably the UserControl or main layout control that hosts the listbox.
State changes and animations need to be in the style though so... you still cant get at the listbox item, just the element inside it in the data template.
Oh and if doing drag and drop HitTest is now protected so that will make the Drop harder.

since today you can download the final 2.0 version of Silverlight with some add ons, check the Scott's web log

I've been trying to do the same thing in WPF,
but have only found many buggy implementations.
One person has guided me towards the blog of Beatriz Costa,
and from what I remember she's one of those rare geniouses,
so I suggest you read that as well... I know I will
Blog of Beatriz Costa

Related

Implementing a "fisheye" view with a ListBox

I am new to Windows Phone Programming. In my application, I Have a listbox which lists the phone contacts. Currently it is listed as a regular list with equal size for list items in the UI.I am looking to modify the front end like this :
I dont want to have different sizes /back ground color for each list items rather a fixed UI and let the lists scroll through it and the list item in the view, at any time, should be displayed as in the picture.
I dont expect any codes as answers but any examples are welcome too, just want to know using what feature this kind of functionality is possible so that i can do my reading!
Thanks,
Deepak
It would be difficult to modify an existing control (ListBox for example) to act like this, so your best bet would probably be an ItemsControl with its RenderTransform set as a TranslateTransform.
If you place a Rectangle (with Fill="Transparent") over the ItemsControl, you can attach handlers to the ManipulationStarted, ManipulationDelta, and ManipulationCompleted events to control the "scrolling" by setting the TranslateTransform's Y offset.
To resize the items in the list there are two options: a custom panel or manual setting.
Custom Panel
You could create a custom Panel implementation that will appropriately resize its Children based on a property you would create to represent the scroll position. Set the ItemsControl to use your panel, and either through binding or attaching a handler to the panel's Loaded event and keeping a pointer to the panel, update the aforementioned property from inside the ManipulationDelta handler.
Manual Setting
From inside of the ManipulationDelta handler, you can also calculate the various heights of the boxes and use MyItemsControl.ItemContainerGenerator.ContainerFromIndex to get the visual for each item and set its height.
I would suggest putting this all inside of a custom UserControl.
You may have issues with clipping using the TranslateTransform but hopefully this will get you started. Unfortunately, this looks like a rather difficult control to try making as your first windows phone project!
So Finally I did manage to find a way to do it.
First approach was as #Murkaeus suggested, Using UserControl and ManipulationDelta event handler. However for some reason the manipulationDelta event was triggered only for 2 finger gestures (Zoom, Pinch..etc), I have no clue why. And after some trying I had to give up on this.
The next approach was using Listbox itself. The source of the Listbox was set as the List( of Models objects) that I create after reading the contact information from phone. The height and color of the listbox item was bound to a property in my model named "scaleLevel" and was accordingly converted by implementing IValueConvertors to give predefined color and height values for different scale levels.
I created an attached property for the scrollviewer vertical offset like mentioned [here] (http://www.scottlogic.co.uk/blog/colin/2010/07/exposing-and-binding-to-a-silverlight-scrollviewer%E2%80%99s-scrollbars/)!
This event is triggered on change of the vertical offset and every time there is a scroll, I find out which listbox item to be enlarged and which reduced based current vertical offset.
Once I have this information, I change the property ("scaleLevel") of the affected items in the List (of Model) (which is bound to listbox height and color). This change is updated in UI using the INotifyPropertyChanged Event.
I have no idea if this the best way of doing it , but it works well and there is no considerable in updating the UI despite the processing involved.
I would like to hear your opinion about the implementation and any other solution which you feel will work better.

Lazy loading of data from server with ListBox

Quite simple Windows Phone question, but couldn't find anything about it searching the web.
I want to fire an event when a user has scrolled to the end of a ListBox (originally containing 100 items), so that I can asyncronously load some more items from my API.
IntelliSense didn't show any event I thought could be useful - perhaps somebody here can show me in the right direction on how I can have this type of functionality?
Kris
Using whats given here you can detect the end of scrolling and trigger an event on the code behind which will call for more items. Once you add them to your Observable Collection which will be bounded to your listbox's itemsource. The items will appear automatically. I hope it helps :)

GestureListener select bad item when scroll moves

I saw here and in some articles that I should use GestureListener to get Tap from user then use SelectionChanged. I tried it and I like it. But I have problem with it. When my listbox moves (scrolls) and I try tap I get bad item (I get item from last tap). When I scroll and wait for stopping scroll and then tap everything is fine (I get exactly item which I tap on). Anyone else with this problem? Any solution? Thanks
As (according to your tags) you're targetting 7.1, there is no need to have to use a GestureListener to detect Tap events.
All UIElements in Silverlight 4 (which 7.1 is based on) support a built in Tap event. See http://msdn.microsoft.com/en-us/library/system.windows.uielement.tap(v=vs.95).aspx
Using a GestureListener has an unnecessary performance overhead and can cause other issues as you're discovering.
You should use a Tap event in the individual ListBoxItems or the SelectionChanged event on the ListBox not both.
If you create a new Databound Application, the code in the default project files will show an example of how to use SelectionChanged and in that instance trigger a page navigation.
In future, you may also get a better, faster answer by showing the code you are having problems with, not just describing it.

Is it possible to remove and move a row of listbox on itself?

Just like the UITableView on iphone.
users can remove or move a row on UITableView.
There is only one button to switch the UITableView to editing mode.
but for listbox on wp7 , I need 3 buttons, one for removing the selected row, one for moving the row up, one for moving the row down.
Welcome any comment
The Windows Phone ListBox doesn't support these features out of the box, but it would be possible to add them yourself using a DataTemplate.
Here's a blog post about creating a custom DataTemplate for your ListItems.
At a high level, you'll need to create a template that contains:
Enter edit mode button
Delete button
Sort up/down buttons
Then in your code, you'll need to toggle the visibility of the delete and sort buttons, as well as handle user clicks on each of the buttons. Doable, but a fair amount of work.
In my opinion, a better option would be to use a approach that's different from what you might be used to but is more familiar to Windows Phone users: the ContextMenu. This control allows you to pop up a menu when the user performs a long touch (tap-and-hold) on an item.
Here's a good tutorial about incorporating this control into your app.
Take a look at re-order ListBox here. It shows how to retemplate the ListBox.
For removing on item, you just need to remove its data source item. See how to use ObservableCollection.
If you want to show effect when an item is removed, use Event Triggers for the Unloaded event.

How i Scroll web browser control in wp7

i want to swipe webbrowser Control which is on pivot item ,each pivot item
has a web control .i want to swipe with web browser control .
but i don't have any idea.but swiping is necessary in my project .is there any method to doing this if yes then please send me sample code for this ..
This is a bind if you have some different sections of HTML you want to display in a Pivot. If you are targetting WP7 Mango it might be possible for you to convert your HTML to RTF and then use a RichTextBox instead of a WebBrowser. However if your HTML is fairly complex, this probably isn't going to work for you.
Alternatively you could place your WebBrowser in a pivot item with a transparent Rectangle above it in the Z-order. Make sure that Rectangle swallows any gestures and doesn't pass them through to the WebBrowser control - that way you will be able to swipe left and right on the WebBrowser to get the pivot to move.
Next you can use the GestureService on this transparent rectangle to recognize vertical pans/swipes and taps to take you to a full page view of your WebBrowser content. In this full page view you would have a fully interactive WebBrowser control.
You have an issue with competing gestures. Try setting the WebBrowser control to IsHitTestVisible to false. This will mean that you'll be unable to manipulate or scroll the content of the WebBrowser control though.
shanu: if you still need it, check my recent answer at: WP7 Pivot control and a WebBrowser control
There's a bit of info on how to "hack into" the webbrowser and what to do, to (almost) prevent it from stealing your swipes. If you are insane/masochistic enough to try that approach I described there, then in addition to that eventhandling and other configuration/detection, you will have to drive your pivot manually via relevant pivot.selectedindex++/-- on H-swipes detected with your handlers (or you can separate blocking and observing with gesture listener, that may sometimes result in the code being a bit cleaner). I also think you will have to be careful with the selectedindex near to the page ranges. I dont know how pivot behaves if you order it to go further than you page count, and I dont know either if it will animate correctly, if being on the last page you order it to go "wrap around" and go to page 0 via selectedindex=0. It may get "crazy" and rewind back instead of going forward in a circular fashion.. you will have to experiment with that

Resources