In my project I want to preserve scroll position when the user navigates between pages. Currently I want to change position of elements in a GridView. I came up with this test code:
void OnLoaded(object sender, RoutedEventArgs e)
{
ScrollViewer scrollViewer = VisualTreeExtensions.GetVisualChild<ScrollViewer>(gridView);
scrollViewer.ChangeView(100, null, null);
}
However this code doesn't work, when the ScrollViewer is inside the GridView.
Any ideas what could be wrong?
P.S.
I don't want to use ScrollIntoView method because I want to restore the Scroll position exactly as it was.
have you tried using NavigationCacheMode="Enabled"?
If you can't use navigation cache mode, try moving the yourScrollViewer.ChangeView(100,null,null) to yourScrollViewer.OnLoaded.
Related
I'm using GWT PopupPanel to display a popup above a button when user clicks it.
I am setting popup's position and showing it like so:
panel.setPopupPosition(leftPos, topPos);
panel.show();
However, when I inspect the popup's top value after it shows, I see that it is positions slightly lower than what I assigned it.
The issue may be that setPopupPosition changes the values that are passed in:
// Account for the difference between absolute position and the
// body's positioning context.
left -= Document.get().getBodyOffsetLeft();
top -= Document.get().getBodyOffsetTop();
How can I make sure the GWT PopupPanel's position is exactly the values I gave it? setPopupPosition() seems to really be the only way to set the position, but it does some manipulation (which is unnecessary for my use case) to the positions I pass in.
You can use direct access to popup's DOM element to adjust PopupPanel position. But it should be done after calling show() and before making popup visible. Otherwise, you'll may see some "jump" effects.
Example:
PopupPanel popupPanel = new PopupPanel();
...
// this callback will be called after PopupPanel.show(), but before it is shown
popupPanel.setPopupPositionAndShow(new PositionCallback() {
#Override
public void setPosition(int offsetWidth, int offsetHeight) {
Style style = popupPanel.getElement().getStyle();
style.setLeft(100, Unit.PX);
style.setTop(100, Unit.PX);
}
});
I have a hierarchical tree implemented using ListBox. I implemented item reordering method by holding an item and dragging it around.
To do this I intercept item's Hold, ManipulationDelta and ManipulationCompleted events. Because Listbox's ScrollViewer is in ManipulationMode = ManipulationMode.System by default, I need to set it to ManipulationMode.Control to disable it temporarily to be able to drag my item around.
If I won't do that, scrollviewer intercepts my ManipulationDelta events so when user tries to drag the item, he scrolls the scrollviewer instead and my item stays in fixed position.
Normally, after user drops the item i want to set it back to ManipulationMode.System (if I don't the tree structure scrolling remains laggy because item's template is somewhat heavy/complex).
private void ElementHold(object sender, GestureEventArgs e) {
....
_scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
_scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
// works ok
_scrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.Control);
}
private void ElementManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
_scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
_scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
// ▼ this doesn't seem to work.
// ▼ In the debugger ManipulationMode has correct value but scrolling
// ▼ still lags which means that scrollviewer stays in Control mode.
_scrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.System);
}
I've read that I can't switch ManipulationMode after ApplyTemplate() was called, but I also read that it should be possible if done by setting via dependency property instead of standard property.
What am I doing wrong here? Is it impossible to go back to System mode? If I go to other page and back to this one scrollViewer still lags. Only app restart works.
Just set UseOptimizedManipulationRouting="False" to dragging item control to prevent Routing event to scrollviewer
When I add items to the ItemsSource of a LongListSelector, the LongListSelector automatically scrolls to the top. Is there anyway to disable this?
I tried to use the ScrollTo function after loading, but that is not good enough since I want to stay at the exact same scroll position (meaning I don't want the LostListSelector to scroll at all, when I add a new item to its ItemsSource).
The problem was that I used a List instead of ObservableCollection as the ItemsSource for the LongListSelector and that I used the Lists set function, which implements NotifyPropertyChanged, to assign images to the LongListSelector. This NotifyPropertyChanged event causes the LongListSelector to scroll to index 0 of the ItemsSource.
So I solved it by changing the ItemsSource to an ObservableCollection and use Add instead of the setter for the ObservableCollection.
What properties will make the Popup control Shows exactly over the mouse (On real device above the finger position on the screen while touching) in a windows phone application?
The xaml used is
<Grid Grid.Row="2">
<phone:WebBrowser IsScriptEnabled="True" MouseMove="mainBrowserControl_MouseMove" x:Name="mainBrowserControl" />
<Popup Name="ActionMenus" IsOpen="False">
<StackPanel Orientation="Horizontal" Background="Black" >
<Button Name="btnA1" Click="btnAq_Click">Annotation</Button>
<Button Name="btnHq" Click="btnHq_Click">Highlight</Button>
</Popup>
</Grid>
And the code i used for showing Popup is
private void mainBrowserControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
ActionMenus.IsOpen = true;
}
But the position of the Popup is on the top of Grid . How can i make it exactly above the mousepointer (or where the user touched on the screen)
In WPF Popup i can see some more properties like Placement and if we use Placement="Mouse" the popup will shown exactly over Mouse , But this property is missing in Windows phone
As you have not made any Rows in your Grid, any element added to the Grid will be placed on top of all other elements.
In order to place the popup where you want it, you must find out where the user tapped. It can be found in the MouseEventArgs input to the method:
http://msdn.microsoft.com/en-us/library/system.windows.input.mouseeventargs.getposition(v=vs.110).aspx
Then place the ActionMenus accordingly.
At first, if you want to popup show up anywhere on the page you should:
1) Create second grid, that won't have any rows, or columns over your content (with Horizontal and Vertical aligments set to Stretch) - it will be your placing field that will take the whole page.
OR
2) Add to a popup Grid.Row and Grid.Column spans.
Next:
As emedbo said you should catch MouseDown event and get the MouseEventArgs coordinates. And then you can do:
If you selected method 1:
Popup pop = new Popup();
pop.Margin = new Thikness (X,Y,0,0) // To set margin left and top to show popups left top corner under the finger.
Grid.Children.Add(pop);
//Syntax maybe little incorrect, because i'm writting this from my mind
If you selected method 2:
Popup pop = new Popup();
pop.Margin = new Thikness (X,Y,0,0) // To set margin left and top to show popups left top corner under the finger.
pop.*** //Here must be added Rowspan and Columnspan of the parent container
Grid.Children.Add(pop);
//Syntax maybe little incorrect, because i'm writting this from my mind
I have a JFrame with a JTextArea: by clicking on this TextArea a JPopupMenu appears with two items "Clear" and "Save".
private void jTextArea1MousePressed(java.awt.event.MouseEvent evt) {
jPopupMenu1.setVisible(true);
}
My question is: this popup always appears at position (0,0) but I would like to show pop where mouse is clicked, inside or relative to the TextArea.
I have try setLocation(x,y) but this methods always prompt in a fixed location and it is not what I am seeking for, and it is not available a method such as setLocationRelativeTo(JTextArea());
don't use a mouseListener as trigger to show the popup, instead use the JComponent componentPopupMenu property, like
myTextArea.setComponentPopupMenu(myPopupMenu)
Doing so will show the popup on right click at the mouse position by default. It has the additional benefit of covering keyboard triggered (LAF dependend, F10 on win) popup requests as well.
If for some reason you really need to manually show the popup, the method you're looking for is
myPopup.show(myTextArea, x, y)