通过样式绑定在RadTreeViewItem上设置IsEnabled

时间:2011-02-24 20:05:35

标签: silverlight telerik radtreeview

我将分层集合绑定到 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>

1 个答案:

答案 0 :(得分:2)

这是Silverlight吗?

Silverlight中还没有Style绑定(来自Silverlight 5.0)

Telerik有“容器绑定”,它以类似的方式运行,但是在DataTemplate上设置而不是在样式上设置:

http://www.telerik.com/support/kb/silverlight/treeview/radtreeview-and-hierarchicaldatatemplate.aspx

来自他们的文档:

<telerik:ContainerBindingCollection x:Name="BindingsCollection">  
    <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding Selected, Mode=TwoWay}" />  
    <telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding Expanded, Mode=TwoWay}" />  
</telerik:ContainerBindingCollection>  

然后将其附加到DataTemplate:

telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}" 

希望这适用于您的情况

相关问题