【问题标题】:Silverlight TreeMap Binding Text with Property of a list itemSilverlight TreeMap 绑定文本与列表项的属性
【发布时间】:2011-08-23 03:15:33
【问题描述】:

我的 ViewModel 类中有一个 MyObject 集合,名为:ListObjects = List<MyObject>

每个 MyObject 对象都有一个集合属性:List<MyInnerObject>

每个 MyInnerObject 都有一个属性:字符串类型的名称。

将数据上下文设置为 ListObjects 是可行的。我想将TextBlock's Text 属性绑定到:

ListObjects[0].MyInnerObjectList[0].Name <- ListObject collection's first item's MyInnerObjectList's first item's Name property.

如何设置&lt;TextBlock&gt;的绑定路径属性来实现?

我试过了:

<TextBlock Text={Binding Path=ListObjects[0].MyInnerObjectList[0].Name"/> 

<TextBlock Text={Binding Path=ListObjects[0]/MyInnerObjectList[0]/Name"/> 

没用

谢谢

【问题讨论】:

    标签: c# silverlight


    【解决方案1】:

    Silverlight 允许您bind indexer

    所以,你的第一次尝试应该成功。像这样编写正确的绑定:

    <TextBlock Text="{Binding Path=ListObjects[0].MyInnerObjectList[0].Name}"/>
    

    当然,TextBlock的DataContext中有ViewModel对象。

    祝你好运。

    【讨论】:

      猜你喜欢
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 2011-03-06
      • 2010-10-15
      • 2015-05-30
      • 2013-03-25
      相关资源
      最近更新 更多