次のコードが与えられます:
<Window x:Class="WpfApplication76.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<CollectionViewSource x:Key="myCol">
<CollectionViewSource.Source>
<col:ArrayList>
<ListBoxItem>Uno</ListBoxItem>
<ListBoxItem>Dos</ListBoxItem>
<ListBoxItem>Tres</ListBoxItem>
</col:ArrayList>
</CollectionViewSource.Source>
</CollectionViewSource>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{StaticResource myCol}" />
<ListBox ItemsSource="{Binding Source={StaticResource myCol}}" />
</Grid>
</Window>
この例では、
<ListBox ItemsSource="{StaticResource myCol}" />
「CollectionViewSource」オブジェクトにバインドできないというエラーが表示されます。
しかし、他のリストボックス:
<ListBox ItemsSource="{Binding Source={StaticResource myCol}}" />
完全にうまくバインドします。
だから私の質問は、なぜ一方が機能し、もう一方が機能しないのかということです。最後に、両方のItenSourceが同じ「CollectionViewSource」オブジェクトに設定されていませんか?
ありがとうございました。