【问题标题】:XAML ~ Need help with the Binding syntax for collection of objectsXAML ~ 需要有关对象集合的绑定语法的帮助
【发布时间】:2010-06-29 21:11:55
【问题描述】:

我正在尝试将对象列表绑定到 ItemsControl。该对象只有两个属性:Movie(字符串)和 Actors(字符串数组)。我可以让绑定在电影中正常工作。但我无法弄清楚 Actors 数组的绑定。

<ItemsControl x:Name="MovieList">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Width="100">
                <Border Margin="2">
                    <TextBlock Text="{Binding Movie, Mode=OneWay}" />
                </Border>
                <ListBox ItemsSource="{Binding Actors, Mode=OneWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <controlsToolkit:WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

有什么建议吗?

【问题讨论】:

    标签: silverlight xaml


    【解决方案1】:
    <ListBox ItemsSource="{Binding Actors, Mode=OneWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
    

    这是错误的……你必须告诉它你想在actors集合中绑定什么。

    例如 {Binding Path=ActorName}...因为您只有一种方式,您可以使用 displaymemberpath 来代替:DisplayMemberPath="ActorName"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 2011-11-04
      相关资源
      最近更新 更多