通过样式绑定在 RadTreeViewItem 上设置 IsEnabled
我将分层集合绑定到 RadTreeView,效果很好。我现在想要根据名为 PermissionID 的布尔属性的值禁用项目。
当我尝试此操作时,我的模块(这是一个 PRISM 应用程序)的 InitializeComponent
失败并出现异常:
{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>
I'm binding a hierarchical collection to a RadTreeView, working great. I now want to disable items based on the value of a boolean property called PermissionID.
When I try this, the InitializeComponent
of my module (this is a PRISM app) fails with an exception:
{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()}
It looks like it's saying the IsEnabled property is read-only, but it's not.
Here's my 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是银光吗?
Silverlight 中还没有样式绑定(在 Silverlight 5.0 中出现)
Telerik 有“容器绑定”,其作用方式类似,但在 DataTemplate 上设置,而不是在样式上设置
: telerik.com/support/kb/silverlight/treeview/radtreeview-and-hierarchicaldatatemplate.aspx" rel="nofollow">http://www.telerik.com/support/kb/silverlight/treeview/radtreeview-and-hierarchicaldatatemplate。 aspx
来自他们的文档:
然后将其附加到 DataTemplate:
希望这适用于您的情况
Is this Silverlight?
There are no Style bindings in Silverlight just yet (coming in Silverlight 5.0)
Telerik have "Container Bindings" which act in a similar way but are set on the DataTemplate and not on the Style:
http://www.telerik.com/support/kb/silverlight/treeview/radtreeview-and-hierarchicaldatatemplate.aspx
From their docs:
And then this is attached to the DataTemplate:
Hopefully this will work in your case