2015-01-07 55 views

回答

2

看來,一個需要註冊的處理程序來更新佈局:

auto inputpane = InputPane::GetForCurrentView(); 
inputpane->Showing += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged); 
inputpane->Hiding += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged); 

來處理該事件,我們可以在事件參數使用OccludedRect我們可以從中提取由鍵盤所採取的高度。首先,我們在XAML中保留一些UI元素,例如SpaceForKeyboard。例如:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="Auto"/> 
    <Grid.RowDefinitions> 
    <Grid Grid.Row="0"> <!-- Main UI goes here --> </Grid> 
    <Grid Grid.Row="1" x:Name="SpaceForKeyboard"> <!-- Dummy grid for the keyboard --> </Grid> 
</Grid> 

然後在處理程序,只是改變大小的保留空間:

void MainPage::OnInputPaneVisibilityChanged(InputPane^ sender, InputPaneVisibilityEventArgs^ args) 
{ 
    SpaceForKeyboard->Height = sender->OccludedRect.Height; 
} 

簡單,因爲它應該是,當顯示/隱藏鍵盤,調用處理程序並設置(或隱藏)虛擬網格以佔據顯示鍵盤的空間。