2017-12-25 31 views
1

UWP에서 기본적으로 지원되지 않기 때문에 현재 WinRT xaml ToolKit TreeView 구성 요소를 사용하려고합니다.UWP - WinRT xaml 툴킷 FlyView의 TreeView, 플라이 아웃 후 선택 변경

TreeView는 버튼 플라이 아웃에 있습니다. 버튼을 누르면 플라이 아웃이 나타나 트리에서 항목을 선택할 수 있습니다. 내가 뷰 모델에서 SelectedItemChanged 이벤트에 명령을 바인딩 :

<Button 
    x:Name="btnFilter" 
    HorizontalAlignment="Right" 
    Command="{Binding OpenFiltersCommand}" 
    Style="{StaticResource SecondaryMenuButtonStyle}"> 
    <StackPanel Orientation="Horizontal"> 
    <Image 
     Width="28" 
     Margin="0,0,4,0" 
     Source="{StaticResource FilterIcon}" /> 
    <TextBlock x:Uid="Filter" Style="{StaticResource GrayTextBlockStyle}" /> 
    </StackPanel> 
    <FlyoutBase.AttachedFlyout> 
    <controls1:CustomFlyout IsOpen="{Binding IsFiltersOpen, Mode=TwoWay}" Parent="{Binding ElementName=btnFilter}"> 
     <controls2:TreeView 
      ItemContainerStyle="{StaticResource DefaultTreeViewItem}" 
      ItemTemplate="{StaticResource TreeViewItemTemplate}" 
      ItemsSource="{Binding BuildingTree}" 
      Style="{StaticResource DefaultTreeViewStyle}"> 
      <i:Interaction.Behaviors> 
       <core:EventTriggerBehavior EventName="SelectedItemChanged"> 
       <core:InvokeCommandAction Command="{Binding ChangeRoomCommand}" /> 
       </core:EventTriggerBehavior> 
      </i:Interaction.Behaviors> 
     </controls2:TreeView> 
     </controls1:CustomFlyout> 
    </FlyoutBase.AttachedFlyout> 
</Button> 

내가 트 리뷰에서 항목을 선택하면, 그것은해야하지만 나중에 내가 다시 플라이 아웃과 이벤트가 발생을 닫으 등 SelectedItemChanged 이벤트가 발생합니다. 두 번째로 일반적으로 새로 선택한 요소가 현재 부모 다음에 있음을 알립니다. 내가 처음 --1.1 요소로 실행됩니다 SelectedItemChanged --1.1 선택한다면

1 
--1.0 
--1.1 
--1.2 
2 
--2.0 
--2.1 

, 그리고 이후는 새로운 선택 항목으로 2 발광합니다 : 그래서 예를 들어 나는이 구조를 가지고있는 경우.

참고 : ViewModel에서 닫을 수있는 CustomFlyout 구성 요소를 사용하고 있지만 일반 플라이 아웃으로 이것을 테스트했지만 바깥 쪽을 클릭하여 플라이 아웃을 닫은 후에도 동일한 문제가 발생합니다.

업데이트 : WinRT 코드를 다운로드하고 로컬로 TreeView 구성 요소를 디버깅하기 시작했습니다. TreeViewItem.cs 나는이 기능에 문제의 원인을 발견했습니다 : 요소가 그것의 부모 찾아 트리에서 위쪽으로 이벤트를 전파 방지에 실패 가끔 포커스를 얻었을 때 나는 무엇을 말할 수에서

protected override void OnGotFocus(RoutedEventArgs e) 
    { 
     // Since the GotFocus event will bubble up to the parent 
     // TreeViewItem (which will make it think it's also selected), it 
     // needs to ignore that event when it's first been handled by one of 
     // its nested children. We use the IgnoreNextGotFocus flag to 
     // notify our parent that GotFocus has already been handled. 
     TreeViewItem parent = ParentTreeViewItem; 
     if (parent != null) 
     { 
      parent.CancelGotFocusBubble = true; 
     } 

     try 
     { 
      if (Interaction.AllowGotFocus(e) && !CancelGotFocusBubble) 
      { 
       // Select the item when it's focused 
       Select(true); 

       // ActivateAsync the selection 
       IsSelectionActive = true; 
       UpdateVisualState(true); 

       Interaction.OnGotFocusBase(); 
       base.OnGotFocus(e); 
      } 
     } 
     finally 
     { 
      CancelGotFocusBubble = false; 
     }    
    } 

.

는 또한 자신의 GitHub의 저장소

답변

1

나는이 WinRT 트 리뷰 구성 요소에서 문제를하지만 내가 바인딩하여이 동작을 (하드 수정)를 방지하기 위해 관리되는 것 같다 이전에 말했듯이 "의 IsEnabled"속성 상 issue을 열었습니다 내 ViewModel에서 IsFiltersOpen 속성으로.

이 방법으로 요소를 선택하면 Flyout을 닫고 TreeView 구성 요소를 사용하지 않도록 설정하여 업데이트하지 못하도록합니다.