开发者

XAML ~ Need help with the Binding syntax for collection of objects

I am trying to bind a List of objects to an ItemsControl. The object has only two properties: Movie (a string) and Actors (an array of string). I can get the binding to work fine for the Movie. But I can't figure out the binding for the Actors array.

<ItemsControl x:Name="MovieList">
    <ItemsControl.ItemTemplate>
 开发者_StackOverflow中文版       <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>

Any suggestions?


<ListBox ItemsSource="{Binding Actors, Mode=OneWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

this is wrong...you have to tell it what you want to bind to in the actors collection.

{Binding Path=ActorName} for example...since you only have it one way you could use displaymemberpath instead and just go: DisplayMemberPath="ActorName"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜