问题
Based on the link scrollviewer to scroll to textbox position
I tried to resolve scrolling issue when keyboard is launched but there is a problem in landscape mode.
Problem in using (App.Current as App).RootFrame.RenderTransform = new CompositeTransform(); in landscape mode.
Above solution helped me to generate a behaviour similar to New Appointment page as in the default calendar app for windows phone 7.5.
But this (App.Current as App).RootFrame.RenderTransform = new CompositeTransform();does not work for landscape orientation of a page.
It works as expected in potrait mode, but on changing orientation(turning device), page does not automatically convert for landscape view, instead the page appears similar to portrait view with its width and height changed.
Initially i had placed this in App class (App.Current as App).RootFrame.RenderTransform = new CompositeTransform();
it is Working fine in portrait mode. But in landscape mode, it did not work as expected. So i reverted to original value for (App.Current as App).RootFrame.RenderTransform which i had stored in a static variable in App class, before assigning the composite transform in orientation changed method. This made page to alter correctly for landscape mode.
Now placed(App.Current as App).RootFrame.RenderTransform = new CompositeTransform(); in textbox focus method, on click of the textbox, landscape page turns portrait automatically with its width and height changed and doesn't even look similar to the correct portrait view. I don't know what exactly is happening. Any help could be appreciated.
Any idea to fix this issue, Awaiting your valuable response.
回答1:
In landscape mode, based on Landscape Left or Landscape Right, use the following code
if(orientation == PageOrientation.LandscapeLeft) (App.Current as App).RootFrame.RenderTransform = new CompositeTransform() { Rotation = 90, TranslateX = 480 }; else (App.Current as App).RootFrame.RenderTransform = new CompositeTransform() { Rotation = -90, TranslateY = 800 };
This will alter your page correctly for Landscape mode also. This will prevent page header from disappearing on launch of keyboard. Scrolling to specific textboxes inside scrollviewer needs to be handeled by ScrollToVerticaloffset() in the GotFocus() events of specific textboxes.
来源:https://stackoverflow.com/questions/14795865/scrolling-is-disabled-limited-when-keyboard-is-popped-up-in-windows-phone-7-5