2

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

1 回答 1

2

这是银光吗?

Silverlight 中还没有样式绑定(在 Silverlight 5.0 中提供)

Telerik 有“容器绑定”,其行为方式类似,但设置在 DataTemplate 而不是 Style 上:

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

希望这适用于您的情况

于 2011-02-24T22:34:04.363 回答