1
我在我的代码中实现了一个MVVM TreeView。 我想的是,重点将是在我的树最新的树型视图(我不断更新树形视图) 我尝试了以下内容:IsMocused in MVVM TreeView
<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");
}
}
}
但我得到以下错误:
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?