リストビューをエレガントな方法で更新したいと考えています。
これは私のコードです:
ObservableCollection<Track> tracks = new ObservableCollection<Track>();
Track track = new Track();
Tracks.AddRange(track); // collection add a track, and list view updates too
Task.Factory.StartNew(() =>
track.GetInfo(); // this operation might require some times to update
// here I need to notify that my object is updated
);
ObservableCollection 内のオブジェクトのバインドを強制的に更新するにはどうすればよいですか?
これは私のuserControl.xamlです
<UserControl.Resources>
<local:TimeConverter x:Key="timeConverter" />
<local:IndexConverter x:Key="indexConverter" />
<CollectionViewSource x:Key="trackList" Source="{Binding Path=TrackList.Tracks}"/>
</UserControl.Resources>
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" Margin="2, 5, 2, 5">
<Button Name="btn_addtrack" Command="{Binding AddTrack}" Content="+" />
</StackPanel>
<ListView Name="lv_tracklist"
DataContext="{StaticResource trackList}"
ItemsSource="{Binding}"
>
<ListView.View>
<GridView>
<GridViewColumn Header="#" Width="20" DisplayMemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource indexConverter}}" />
<GridViewColumn Header="Title" DisplayMemberBinding="{Binding Title}"/>
<GridViewColumn Header="Artist" DisplayMemberBinding="{Binding Artist}"/>
<GridViewColumn Header="Length" DisplayMemberBinding="{Binding Length, Converter={StaticResource timeConverter}}" />
<GridViewColumn Header="Path" DisplayMemberBinding="{Binding Location}"/>
</GridView>
</ListView.View>
</ListView>
</DockPanel>