2011-02-24 50 views
2

我將分層收集綁定到RadTreeView,效果很好。我現在想要基於名爲PermissionID的布爾屬性的值禁用項目。通過樣式綁定在RadTreeViewItem上設置IsEnabled

當我嘗試這一點,我模塊的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> 

回答

2

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

希望這會在你的情況

+0

這個工作的工作!我必須在HierarchicalDataTemplate上設置BindingCollections,並且完全按照我的意願禁用這些項目。謝謝!! – 2011-02-25 02:31:38

相關問題