0
私はWPFとデータバインディング、 に新たここで私はちょうど正常に動作リストボックスを持っています:なぜ私のリストボックスのデータバインディングはDataContextを使用して動作していないのですか?
<ListBox
x:Name="listBox" ItemsSource="{Binding Path=AllFriends}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
は今、私はDataContextのを試してみたいので、私が使用:
<UserControl.Resources>
<CollectionViewSource
x:Key="FriendsGroups"
Source="{Binding Path=AllFriends}"
>
</CollectionViewSource>
</UserControl.Resources>
<ListBox
x:Name="listBox"
DataContext="{StaticResource FriendsGroups}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
しかし、この1つはあります働いていない。 理由を教えていただけたらと思います。