2
我將分層收集綁定到RadTreeView,效果很好。我現在想要基於名爲PermissionID的布爾屬性的值禁用項目。通過樣式綁定在RadTreeViewItem上設置IsEnabled
當我嘗試這一點,我模塊的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>
這個工作的工作!我必須在HierarchicalDataTemplate上設置BindingCollections,並且完全按照我的意願禁用這些項目。謝謝!! – 2011-02-25 02:31:38