How to detect scroll to top in LongListSelector? - silverlight

For WP8, I am using LongListSelector to display list of items. I need to detect when the user has scrolled to top to load previous items in the list.
I have tried using ItemRealized event to detect when top element has been realised. There are couple of references where it is used to detect 'scroll to bottom'.
http://rahulpnath.wordpress.com/2013/03/03/windows-phone-series-incremental-loading/#comments
http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e
But this event gets fired for top element even when that user hasn't yet scrolled to that item. So, that doesn't for me to detect 'scrolling to top'.
Is there any way to detect this?

Use the technique you are already using (ItemRealized), but just ignore the first event (since that's when the list is created. You can ignore it by simply setting a flag:
private bool _firstRealized = false;
void yourLLS_ItemRealized(object sender, ItemRealizationEventArgs e)
{
// do your item detection here. For example:
if (Data[0] == e.Container.Content) {
// then
if (!_firstRealized)
{
_firstRealized = true;
}
else
{
// woo - we've scrolled to top! Do your stuff
}
}
}

You can simply use this reference to get vertical offset
Get vertical offset of LongListSelector
and when vertical offset is 0 (or less than 10) then you are on top ViewPort.

Related

Event to fire after a System Windows Form element has been updated

I have a Windows form with a series of list boxes
The contents of subsequent lists change based on choices in earlier ones
All the boxes are bound to a BindingList with OnListChanged enabled
I use this to retain user-specified 'checked' items when elements are added or removed
However, I note that if I add an item to the list, it appears to update the UI only after all the other events have been fired
I've looked at the events I would expect to fire on the CheckedListBox, and in the related ViewModel, in order to catch the one which adds an item to the list, but so far without success
Can someone please advise me which event would allow me to call my 'CheckBoxes' method after the UI has been updated, otherwise they all get set to blank again until the form is closed and opened
private void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// I've removed the debug statements, but this event when the bound list updates is fired before the UI updates
}
private void teams_checked_list_box_SelectedIndexChanged(object sender, EventArgs e)
{
// same with this event, and the other events like SizeChanged
}
EDITED: On reflection, I realise that the problem occurs because I am not setting the true / false checked flag in the binding, because I couldn't figure out how to do it. If someone could point me in the right direction? Code currently looks like this:
teams_checked_list_box.DataSource = Globals.ThisAddIn.TFSTeamsViewModel.ListOfTeamsFromVM.value;
teams_checked_list_box.DisplayMember = "name";
So basically I am only updating the item name, and the check flag is handled on a later pass
How are you adding items to your list? Are you re-binding the listbox? There are basically two ways you can do this depending on your method of adding items:
If you are re-binding, capture the event BEFORE the item is added. Loop through the CheckedItems property of your list box. Save the values. Add your item. Loop through the NEW values and recheck.
OR
When the user checks the item in the listbox, capture that using the ItemChecked event and then store the value of the item somewhere. (Variable, hidden textbox -- ugly, but it works -- etc.) If you are only adding items to the BOTTOM of your list, you can store the index of the item. If you are re-sorting your list, you'll need to store a unique id to reference the item. (Note: you will also need to REMOVE the checked items from your stored value if the user UN-checks an item in your listbox.) Then, after you add your items to the listbox, loop back through and set the checked value on the appropriate listbox items.

Builder C++ : TTreeView with checkbox items

I need to create a treeview with checkbox node like this image :
How to do that?
thx!
The TTreeView component does not natively support checkboxes, but the standard Windows TREEVIEW control does, via the TVS_CHECKBOXES style:
TVS_CHECKBOXES
Version 4.70. Enables check boxes for items in a tree-view control. A check box is displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box altogether. For more information, see Working with state image indexes.
Version 5.80. Displays a check box even if no image is associated with the item.
Once a tree-view control is created with this style, the style cannot be removed. Instead, you must destroy the control and create a new one in its place. Destroying the tree-view control does not destroy the check box state image list. You must destroy it explicitly. Get the handle to the state image list by sending the tree-view control a TVM_GETIMAGELIST message. Then destroy the image list with ImageList_Destroy.
If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.
To apply the TVS_CHECKBOXES style to a TTreeView component, you should derive a new component and override the virtual CreateParams() method, eg:
class TMyTreeView : public TTreeView
{
protected:
virtual void __fastcall CreateParams(TCreateParams &Params);
};
void __fastcall TMyTreeView::CreateParams(TCreateParams &Params)
{
TTreeView::CreateParams(Params);
Params.Style |= TVS_CHECKBOXES;
}
To assign the checkbox states in code, you can then use the TreeView_GetItem()/TreeView_SetItem() macros to toggle a node's state image index as needed.
Alternatively, a more flexible approach is to simply assign your own TImageList to the TTreeView::StateImages property and fill it with whatever checkbox images you want, and then you can set the TTreeNode::StateIndex property as needed. To react to user input on the checkboxes, use the TTreeView::OnClick and TTreeView::OnKeyDown events to toggle the TTreeNode::StateIndex accordingly:
void __fastcall ToggleTreeNodeCheckBox(TTreeNode *Node)
{
if ((Node) && (Node->StateIndex != -1))
{
if (Node->StateIndex == MyCheckedStateImageIndex)
Node->StateIndex = MyUncheckedStateImageIndex;
else
Node->StateIndex = MyCheckedStateImageIndex;
}
}
void __fastcall TMyForm::TreeView1Click(TObject *Sender)
{
TPoint P;
::GetCursorPos(&P);
// or: P = Mouse->CursorPos;
// or: POINTS pts = MAKEPOINTS(::GetMessagePos()); P = Point(pts.x, pts.y);
P = TreeView1->ScreenToClient(P);
if (TreeView1->GetHitTestInfoAt(P.x, P.y).Contains(htOnStateIcon))
ToggleTreeNodeCheckBox(TreeView1->GetNodeAt(P.x, P.y));
}
void __fastcall TMyForm1::TreeView1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key == VK_SPACE)
ToggleTreeNodeCheckBox(TreeView1->Selected);
}

WPF Exiting "Dropped" Combobox, Items no longer editable?

Friends,
I have a WPF Combobox. When the Combobox is opened, I have the items dynamically generated based upon environment variables. So basically a combobox that is bound to a list that is dynamically changing.
Everything works as expected until I Exit the combobox with the dropdown open to enter another control(another combobox).
When I reopen the first combobox, the items appear to be frozen and no longer bound to the list when INDEED the list is changing and is still bound. Its almost like the binding broke.
When this event occurs, I have attempted to forcefully add items, and that doesn't work either. I can see in the code behind that the combobox now contains the additional items, yet it doesn't appear that contain them in the UI.
What is this black magic? Any way to prevent it? is this some type of Stuck focus issue? Maybe the dropdown isn't re-sizing?
I think i have narrowed it down to the physical dropdown is not re-sizing to the new items.
EDIT*
The controls are dynamically generating, so I have no real hard code to show you other than this.
private void CBControl_DropDownOpened(object sender, EventArgs e)
{
((ComboBox)sender).Items.Add("Option");
}
On this event, I will add an items to the combobox, although the items ARE being added to the list, they are not displayed in the UI.
EDIT 2*
I figured it out, so i have 2 comboboxes, it appears that the 2nd was steeling and holding the focus INSIDE the dropdown. (odd bug)
in order to fix it i needed to release it bu changing the index of the 2nd combo box WHILE it is open.
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
and I had to manage the unintended recursive call.
So, here it is.
You got 2 ComboBoxes. If you Open one then directly click into another, the focus is moved to the second combobox dropdown.
If you make any changes to the first combobox, the changes will not take effect to the style(dropdown resize) UNTIL you release the focus from the 2nd combo box dropdown item. Although the items change will take effect, the resize wont.
to release the focus, you need to open the second combox and change the selected index like so:
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
10 hours of debugging. 5 hours of research. First solution I have found. It may be dirty, but its all I can find.

Adding items to below gridview when dropped on top gridview

On my main page, I have a button and telerik mainRadGridView. When I click my button, I get a popup which is divided it into two regions left and right.
On left, I have a RadTreeView and on right, I have a popupRadGridView.
Initially when my popup is open, the popupRadGridView is disabled. When I drop from left to right for first time in my popup nothing is added to popupRadGridView since it is disable which is correct.
But when I drop for second time on to my disabled popupRadGridView inside my opened popup, there is an element added to my mainRadGridView on my main page which is wrong.
I cannot understand how to stop adding onto my main page. Any help is greatly appreciated.
check for the e.Options.ParticipatingVisualRoots in Drop Event of GridView - should provide you the no of active opened child windows participating in the operation.
For additional information follow this link
Telerik Silverlight
I solved my issue as below
In my mainpage codebehind. I did like below
void mainRadGridView_OnDropInfo(object sender, DragDropEventArgs e)
{
if(e.Options.ParticipatingVisualRoots.Count > 0)
{
return;
}
else
{
do stuff;
}
}

How to impelment iPhone like Drag to Scroll Scrollviewer in WPF

I have a scrollviewer which contains number of buttons and forms. Now I want this application to scroll like in iPhone in touchscreen computers.
I have been trying to modify this tutorial:
Drag scrollable ListView
It implements double click to select the list item. However, I rather wanted to use single click so I changed the following code like this:
// initial source code values
// this registers the double click
isMouseDoubleClick = (e.ClickCount>1);
I changed it to..
// Get initial position of the mouse.
Point initialPos = e.GetPosition(this);
// initialize the isMouseDoubleClick;
isMouseDoubleClick = false
//if the button is pressed and hold (not released yet)..
if (e.ButtonState == MouseButtonState.Pressed) {
// if the hold position is same
if (e.GetPosition(this) == initialPose) {
//if mouse released
if (e.ButtonState == MouseButtonState.Released) {
// set isMouseDoubleClick true;
isMouseDoubleClick = true;
}
}
}
But it does not seems to work.
How does they made it work in iPhone.
The item does not gets selected when touched for a while and also while dragged but it gets selected in a single tap.
How can I make it happen similar in WPF application? A click will select the list item. Click and Hold will not select the list item.

Resources