我将分层集合绑定到RadTreeView,效果很好。我现在想根据名为 PermissionID 的布尔属性的值禁用项目。
当我尝试这个时,InitializeComponent
我的模块(这是一个 PRISM 应用程序)失败并出现异常:
{System.Windows.Markup.XamlParseException: Set property '' threw an exception. [Line: 19 Position: 48] ---> System.NotSupportedException: Cannot set read-only property ''.
at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
--- End of inner exception stack trace ---
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at InventoryModule.Views.NavigationView.InventoryNavigation.InitializeComponent()
at InventoryModule.Views.NavigationView.InventoryNavigation..ctor()}
看起来它说 IsEnabled 属性是只读的,但事实并非如此。
这是我的 XAML:
<UserControl.Resources>
<telerik:HierarchicalDataTemplate x:Key="ItemTemplate" ItemsSource="{Binding vw_Module_Access_Permissions_1}">
<TextBlock Text="{Binding Module_Function_Caption}" />
</telerik:HierarchicalDataTemplate>
<Style x:Key="ItemContainerStyle" TargetType="telerikNavigation:RadTreeViewItem">
<Setter Property="IsExpanded" Value="True"/>
<Setter Property="IsEnabled" Value="{Binding Path=PermissionID}" />
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<telerikNavigation:RadTreeView x:Name="InventoryNavigationTree" ItemContainerStyle="{StaticResource ItemContainerStyle}" ItemsSource="{Binding SecuredModuleFunctions}"
ItemTemplate="{StaticResource ItemTemplate}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<inf:InvokeDelegateCommandAction Command="{Binding OpenView}" CommandParameter="{Binding ElementName=InventoryNavigationTree, Path=SelectedItem}"></inf:InvokeDelegateCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</telerikNavigation:RadTreeView>
</Grid>