Search code examples
silverlighttelerikradtreeview

Setting IsEnabled on RadTreeViewItem through style binding


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>

Solution

  • 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:

    <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>  
    

    And then this is attached to the DataTemplate:

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

    Hopefully this will work in your case