I defined my binding like this:
<TreeView
ItemsSource="{Binding UsersView.View}"
ItemTemplate="{StaticResource MyDataTemplate}"
/>
The CollectionViewSource element is defined as follows:
private ObservableCollection<UserData> users;
public CollectionViewSource UsersView{get;set;}
UsersView=new CollectionViewSource{Source=users};
UsersView.SortDescriptions.Add(
new SortDescription("IsLoggedOn",ListSortDirection.Descending);
UsersView.SortDescriptions.Add(
new SortDescription("Username",ListSortDirection.Ascending);
So far, so good, it works as expected: first, users who logged in alphabetically and then those who are not are displayed in the view.
However, the IsLoggedIn UserData property is updated every few seconds by a background worker thread, and then calls the code:
UsersView.View.Refresh();
in the user interface thread.
, : , , . : , Refresh , 3,5 , ( OutOfMemoryException...)
, , :
- UserData INotifyPropertyChanged
- : IENumerable
<UserData > CollectionViewSource .
- ColletionViewSource List <UserData > ( ) ObservableCollection , .
! ?
EDIT:
:
Resource MyDataTemplate , UserData, , UserData TreeView ItemsSource. ContextMenu, :
<ContextMenu Background="Transparent" Width="325" Opacity=".8" HasDropShadow="True">
<PrivateMessengerUI:MyUserData IsReadOnly="True" >
<PrivateMessengerUI:MyUserData.DataContext>
<Binding Path="."/>
</PrivateMessengerUI:MyUserData.DataContext>
</PrivateMessengerUI:MyUserData>
</ContextMenu>
MyUserData UserControl, UserData. , , .
MyUserData UserControl DataTemplate, ! , ?