我有TreeView
控件,我想將樹節點的IsExpanded
屬性綁定到我的DataSource
項目!Silverlight樹形視圖。無法綁定「IsExpanded」屬性
但我有一個例外:
System.Windows.Markup.XamlParseException occurred
Message=Set property '' threw an exception.
StackTrace:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SilverlightTree.BSTreeView.InitializeComponent()
at SilverlightTree.BSTreeView..ctor()
InnerException: System.NotSupportedException
Message=Cannot set read-only property ''.
StackTrace:
at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
InnerException:
內部異常:
{System.NotSupportedException: Cannot set read-only property ''.
XAML:
<Grid x:Name="LayoutRoot">
<controls:TreeView Name="treeView" SelectedItemChanged="treeView_SelectedItemChanged"
Style="{Binding TreeViewConnectingLines}" BorderBrush="{x:Null}">
<controls:TreeView.ItemTemplate>
<toolkit:HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal" Background="Transparent">
<toolkitDrag:ContextMenuService.ContextMenu>
<toolkitDrag:ContextMenu Loaded="ContextMenu_Loaded"
Opened="ContextMenu_Opened"/>
</toolkitDrag:ContextMenuService.ContextMenu>
<Image Source="{Binding Path=Type.Icon}" Width="20" Height="20" />
<TextBlock Text="{Binding Path=FullDescription}" Height="20"
TextAlignment="Center" HorizontalAlignment="Center" />
</StackPanel>
</toolkit:HierarchicalDataTemplate>
</controls:TreeView.ItemTemplate>
<controls:TreeView.ItemContainerStyle>
<Style TargetType="controls:TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded}"></Setter>
</Style>
</controls:TreeView.ItemContainerStyle>
</controls:TreeView>
</Grid>
和數據項:
public interface INode
{
NodeType Type { get; set; }
bool IsSelected { get; set; }
bool IsExpanded { get; set; }
List<INode> Children{get;set;};
}
SDK和工具包的版本?你相信這與'IsExpanded'屬性有什麼關係?如果您刪除了「ItemContainerStyle」,那麼異常消失了嗎? – AnthonyWJones 2010-07-23 09:04:28
「如果刪除ItemContainerStyle,異常消失了嗎?」 是的!異常消失! 工具包:http://www.microsoft.com/silverlight/ – Evgeny 2010-07-23 09:28:33