但我有一个例外:
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;};}解决方法 最快的方法是将TreeVIEw和TreeVIEwItem子类化,例如:
public class BindableTreeVIEwItem : TreeVIEwItem{ protected overrIDe DependencyObject GetContainerForItemOverrIDe() { var itm = new BindableTreeVIEwItem(); itm.SetBinding(TreeVIEwItem.IsExpandedProperty,new Binding("IsExpanded") { Mode = BindingMode.TwoWay }); return itm; }}public class BindableTreeVIEw : TreeVIEw{ protected overrIDe DependencyObject GetContainerForItemOverrIDe() { var itm = new BindableTreeVIEwItem(); itm.SetBinding(TreeVIEwItem.IsExpandedProperty,new Binding("IsExpanded") { Mode = BindingMode.TwoWay }); return itm; }}
不幸的是,当您执行子类化时,您将丢失TreeVIEw的默认主题.这是Silverlight主题概念的弱点.因此,您可以使用自定义的附加属性或行为来遍历树,并从外部设置绑定.因为树节点是按需生成的,尽管如此,您必须为尚未渲染的每个节点收听一次Expanded事件,然后在等待该节点的每个子节点的事件处理程序中设置绑定布局通行证
总结以上是内存溢出为你收集整理的wpf – Silverlight树视图.无法绑定“IsExpanded”属性全部内容,希望文章能够帮你解决wpf – Silverlight树视图.无法绑定“IsExpanded”属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)