2011-12-29 4 views
1

내 코드에서 MVVM TreeView를 구현했습니다.MVVM TreeView에서 IsFocused

<TreeView ItemsSource="{Binding NotificationViewModel}" Name="MainTree"> 
    <TreeView.ItemContainerStyle> 
     <!-- This Style binds a TreeViewItem to a NotificationViewModel. --> 
     <Style TargetType="{x:Type TreeViewItem}"> 
      <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> 
      <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> 
      <Setter Property="IsFocused" Value="{Binding IsFocused, Mode=TwoWay}" /> 
     </Style> 
    </TreeView.ItemContainerStyle> 

와 뷰 모델에 :

// Constructor 
public NotificationListViewModel(Notification notification) 
{ 
    _notification = notification; 

    _activityListViewModel = new ObservableCollection<ActivityListViewModel>(); 

    _isSelected = true; 

    _isFocused = true; 
} 


private bool _isFocused; 

public bool IsFocused 
{ 
    get { return _isFocused; } 
    set 
    { 
     if (value != _isFocused) 
     { 
      _isFocused = value; 
      this.OnPropertyChanged("IsFocused"); 
     } 
    } 
} 

하지만 난 내가 초점이 내 트리에서 최신 TreeViewItem에있을 것입니다 원하는 (내가 트 리뷰를 업데이트 계속)를 나는 다음과 같은 시도 다음 오류가 발생합니다 :

Error 1 The Property Setter 'IsFocused' cannot be set because it does not have an accessible set accessor. Line 115 Position 29. C:\My Visual Studio Projects\MainTreeView\View\NotificationListView.xaml 115 29

IsSelected 및 IsExpanded와 같은 포커스를 구현할 수없는 이유는 무엇입니까?

답변

1

속성 IsFocused은 읽기 전용이므로 컨트롤에 포커스를 설정할 수 없습니다. 좀 더 자세한 내용은 UIElement.IsFocused on MSDN을 참조하십시오.

대신 트 리뷰에서 Focus() 메소드를 사용할 수 있습니다.

관련 문제