【问题标题】:Setting IsEnabled on RadTreeViewItem through style binding通过样式绑定在 RadTreeViewItem 上设置 IsEnabled
【发布时间】:2011-07-03 20:22:21
【问题描述】:

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

【问题讨论】:

    标签: silverlight telerik radtreeview


    【解决方案1】:

    这是 Silverlight 吗?

    Silverlight 中还没有样式绑定(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}" 
    

    希望这对你有用

    【讨论】:

    • 这成功了!我必须在 HierarchicalDataTemplate 上设置 BindingCollections,它会完全按照我的意愿禁用这些项目。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 2019-05-25
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多