(Windows Phone 8.1) In my app, I have a MainPage with a listbox. NavigationCacheMode is set to required to preserve the state when navigating back to the same page.
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
// cache page
this.NavigationCacheMode = NavigationCacheMode.Required;
}
So when I go to another page and come back to my MainPage everthing looks the same as I left it. The Listbox is also in the corrent position. But whenever I touch it, it will jump to the top before it scrolls...
How can I make it so that it resumes scrolling before going to the top first?
EDIT: solved
Seems like Listbox is bugged in WP8.1, use ListView instead!
I had the same problem and figured out that it's primarily the chosen ItemsPanelTemplate which causes the Bug.
When using a ListView, the standard ItemsPanelTemplate is ItemsStackPanel, which works fine. If you change that to VirtualizingStackPanel (standard for ListBox) the bug appears. But only on Windows Phone, for Windows it works like expected.
So I assume that, when you like to use ListBox instead of ListView, you have to use ItemStackPanel as ItemsPanelTemplate to preserve the scroll position via NavigationCacheMode.
Related
In the first page I have a navigation view and have enabled page cache on this page. Without pushing any other page on this, I can switch between tabs. But once I navigate to a new page and then pop back the navigation stops working. If I disable the cache all of the state is lost which I dont want. Tried setting it to required too. The pages are not heavy I tested by creating a sample app with just a textblock.
<Page
...
NavigationCacheMode="Required">
# Navigation View goes here
</Page>
In the page pushed on top of the main navigation page, I have below code to dismiss the page.
private void OnCloseClick(object sender, RoutedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.CanGoBack) { rootFrame.GoBack(); }
}
Once gone back the navigation simply does not work, what am I doing wrong here ?
Stumbled across the same problem and looks like there's a bug in NavigationView class. Long story short, it is not able to properly recover after Load-Unload-Load cycle (e.g. when it is removed from and added back to view hierarchy - which happens when you navigate from page and back) and stops working.
Update: Checked with NavigationView from WindowsUI SDK. Works like a charm, only settings item seems to be broken yet it still has a problem with selecting items with SelectsOnInvoked set to false (aka conditional select).
I have a question that I believe is a little bit weird due to the lack of information I'm finding online.
In my program, there is a UIPageViewController that is overlayed by a UIPageControl. In my UIPageViewController, each View Controller has a table inside with a number of items. With pages being the name for my UIPageControl, when I use pages.UserInteractionEnabled = false; my tap gesture taps underneath of the UIPageControl and taps one of the items in the table, pushing a new view controller for that item. I don't want that to happen, but I also don't want the typical functionality of UIPageControl, which is to scroll left or right depending on the location of the touch. I want this UIPageControl on my user interface for purely the indication of how many pages and which page is the current page.
I've tried removing any existing gesture recognizers from the pages.GestureRecognizers collection and that didn't work. I've tried setting pages.AllTouchEvents += (sender, e) => { return; } which also did nothing.
A thought: I have the UIPageControl as a view that spans the width of the view. Could I add a UIView and then add the UIPageControl as a subview of that, and then call its .SizeToFit() method?
In any case, thanks for taking a look. Any help and/or ideas are appreciated.
Please try pageControl.DefersCurrentPageDisplay = true; to achieve your effect.
When it is set True, the current page indicator will not be rendered until we set the pageControl's CurrentPage to change its selected indicator.
I am working in Windows phone 8. In One of the pages of my app there is a LongListSelector and under it there is a TextBox. When the TextBox get focused then keyboard is opened. As the keyboard is opened then the LongListSelector is shifted up by keyboard height. If I maintain the margin of the LongListSelector by keyboard's offset then some of the items of LongListSelector go under the keyboard.
All I want to do is when keyboard is shown then margin will be updated and the previous focused item of the LongListSelector should not go under keyboard. Here I don't want to use ScrollTo() function to scroll a specific item of LongListSelector.
Any suggestion or help will be appreciated.
Here is an example of workaround. Though this code is for WP8. You will have to make some changes to make this working for WP8.1 like :
Tap in xaml will be replaced by Tapped.
((App)Application.Current).RootFrame.RenderTransform = new CompositeTransform();
will be replaced by
Window.Current.Content.RenderTransform = new CompositeTransform();
Dispatcher.BeginInvoke(() => {}will be replaced by
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{}
let me know if you face any issue.
I am having a WinForms control, inside that I have a TableLayoutPanel which holds multiple ElementHosts and each ElementHost contains a WPF control.
Everything works fine except when the size of controls is bigger then window and ScrollBar is there; when I scroll down, the controls get rendered distorted, like this -
On maximizing the window or re-sizing it, controls render properly
(reducing the size such that controls go out of visible area and then increase the size again to bring them back in visible area)
This doesn't happen with WinForms control in the same window just the WPF ones; any idea why this is happening and any solution for this?
this.Loaded += delegate
{
var source = PresentationSource.FromVisual(this);
var hwndTarget = source.CompositionTarget as HwndTarget;
if (hwndTarget != null)
{
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}
};
Try using that in the wpf control you are hosting. This is a known rendering issue of the the wpf controls that are hosted in win forms. Changing the rendering mode to software only will solve the problem.
I had a similar problem and solved forcing a refresh of the ElmenetHost in the scroll event of the TableLayoutPanel
Ok, this is gonna sound like total B.S. but it worked for me: in the Load event of your form, resize the form.
public class MyForm : Form
{
public MyForm()
{
Load += (o, e) => { Width -=1; Width +=1; };
}
}
After the form has been resized, I could not force a display issue.
I have a full screen WPF application built for a touch monitor, and I have some Listboxs on the main screen.
When I flick the 'Listbox' it scrolls fine, but when it gets to the end of the list, the entire application gets pulled down from the top of the screen, can I stop this behavior somehow?
Has anyone else seen this?
Yes, that default behaviour of the ListBox (or rather, the ScrollViewer inside the default ListBox template) is weird - when I first came across it, I thought it must be a practical joke. In fact, it's really hard to find any documentation about it - but it is briefly mentioned here:
The ManipulationBoundaryFeedback event enables applications or components to provide visual feedback when an object hits a boundary. For example, the Window class handles the ManipulationBoundaryFeedback event to cause the window to slightly move when its edge is encountered.
So, a way around it is to handle ManipulationBoundaryFeedback on the ListBox, and set Handled to true:
<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback">
// ...
</ListBox>
Code-behind:
private void OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}