2014-10-06 2 views
2

저는 Windows Store 스타일 WPF 응용 프로그램이 있으며 방금 검색 기능이 추가되었습니다. 앱 표시 줄에서 검색 버튼을 클릭하면 SearchBox이 포함 된 FlyoutPresenterVisible으로 설정합니다. 이 버튼은 오른쪽 아래 모서리에 있습니다. 키보드가있는 컴퓨터에서는 잘 작동하지만 가상 키보드 인 InputPane이 열리면 문제가 발생합니다. 먼저, 키보드가 상자를 덮었습니다. 상자에 포커스가있을 때 상자의 여백을 확인하고 조정하여이 문제를 해결했지만 페이지를 맨 위와 맨 아래로 스크롤하면 컨트롤이 페이지에서 움직이기 시작합니다. 여기 내 최소한의 코드입니다XAML의 고정 위치 지정

XAML :

<Grid Background="White" x:Name="MainGrid"> 

    <!-- App Bar with Search button --> 
    <AppBar x:Name="BAppBar" VerticalAlignment="Bottom"> 
     <CommandBar> 
      <CommandBar.PrimaryCommands> 
       <AppBarButton Icon="Find" Label="Search" Click="Search_Click"/> 
      </CommandBar.PrimaryCommands> 
     </CommandBar> 
    </AppBar> 

    <!-- Search button and Close button --> 
    <FlyoutPresenter VerticalAlignment="Top" Name="SearchPop" Visibility="Collapsed"> 
     <StackPanel Orientation="Horizontal"> 
      <SearchBox Name="Search" GotFocus="Search_Focus" LostFocus="Search_Focus"/> 
      <AppBarButton Name="SearchClose" Icon="Cancel" Click="Search_Close" /> 
     </StackPanel> 
    </FlyoutPresenter> 
</Grid> 

C 번호 :

상자가 화면에 스크롤 사용자에 의해 영향을받지 않을하기위한 것입니다 내가 필요
public partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 

    // Close app bar, show search box, and set margin to bottom of page 
    private void Search_Click(object sender, RoutedEventArgs e) 
    { 
     BAppBar.IsOpen = false; 
     SearchPop.Visibility = Windows.UI.Xaml.Visibility.Visible; 

     SearchPop.Margin = new Thickness(0, MainGrid.ActualHeight - SearchPop.ActualHeight, 0, 0); 
    } 

    // Set margin for opening/closing virtual keyboard 
    private void Search_Focus(object sender, RoutedEventArgs e) 
    { 
     Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing += (s, args) => 
     { 
      double flyoutOffset = (int)args.OccludedRect.Height - SearchPop.ActualHeight; 
      SearchPop.Margin = new Thickness(0, flyoutOffset, 0, 0); 
     }; 
     Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hiding += (s, args) => 
     { 
      SearchPop.Margin = new Thickness(0, MainGrid.ActualHeight - SearchPop.ActualHeight, 0, 0); 
     }; 
    } 

    // Close search 
    private void Search_Close(object sender, RoutedEventArgs e) 
    { 
     SearchPop.Visibility = Windows.UI.Xaml.Visibility.Collapsed; 
    } 
} 

. HTML에서는이를 Fixed Positioning이라고합니다. XAML에서는 기본적으로 가능하지 않지만 해결 방법이 있다는 것을 읽었습니다. 나는이 MSDN 및 SO 링크를 읽고,하지만 그들은 정말 도움이되지 않았다 :

http://social.msdn.microsoft.com/Forums/en-US/9779328a-a7cd-447d-a4ac-bcc952083f43/fixed-positioning-in-wpf?forum=wpf

http://social.msdn.microsoft.com/Forums/windowsapps/en-US/7349d01d-dc0e-4e1c-9327-df90e00fbebf/how-to-handle-the-appearance-of-the-onscreen-keyboard?forum=winappswithcsharp

Popup control moves with parent

+0

OK, 그냥이 질문을 해결하지 못했지만 InputPane이 열려있는 동안 검색 상자를 페이지 맨 위로 이동하여 문제를 해결했습니다. 모든 답변을 주시면 감사하겠습니다. – Hosch250

답변

1

당신은 매우 간단한 방법으로 XAML에서 고정 동작을 시뮬레이션 할 수 있습니다 :

<Grid Background="White" x:Name="MainGrid"> 
    <ContentControl VerticalAligment="Stretch" HorizontalAligment="Stretch"> 
    <!--All other visual controls, the float item will be located over all controls located here, even scrolls viewers--> 
    </ContentControl> 

    <!-- Float item --> 
    <SomeControl> 
    <!--The control you want be over in the fixed position, 
     you can set the layout to it, and locate it where you want 
     just set the Vertical/Horizontal Aligment, margin, height, width--> 
    </SomeControl> 
</Grid> 

(죄송합니다. 코드 샘플에 약간의 sintax 오류가있는 경우이를 즉시 작성했습니다.) 또한 wpf에는 다른 모든 레이어 위에 표시되는 일부 컨트롤이 있습니다.이 요소는 컨텍스트 메뉴, 툴팁 및 꾸미기이며, 시도해 볼 수도 있습니다.

이 아이디어가 도움이되기를 바랍니다.

+0

나는 이것을 확실히 조사 할 것이다. 툴팁에 대해서는 알고 있지만, 마우스를 끌 때 사라집니다. 사용자가 마우스를 닫을 때까지 열려 있어야합니다. 나는이 질문에 대해 글을 올리기 전까지는 꾸미기에 대해 알지 못했지만 이미 살펴 보았지만 Windows Store 앱 (아직)에서는 지원되지 않습니다. 아직 툴팁을 조사하지는 않았지만 그렇게 할 것입니다. – Hosch250

+0

작동하지 않는 것 같습니다. InputPane이 열리면 전체 표가 위로 이동합니다. 내 시스템의 다른 응용 프로그램에서는 이와 같이 작동하지 않으므로 InputPane을 그리드 위로 밀면서 밀어 넣을 수있는 방법이 있어야합니다. 바로 지금, 그게 제가 찾고있는 것입니다. 그 밖의 모든 것들은 쉽습니다. – Hosch250