Guest User

Untitled

a guest
Sep 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. UserDataGrid.Dispatcher.BeginInvoke(new Action(() =>
  2. {
  3. UserDataGridCollection[m_iID].Status = Log;
  4. UserDataGridCollection[m_iID].ID = m_iID;
  5. UserDataGridCollection[m_iID].User = m_sUser;
  6. }
  7.  
  8. UserDataGrid.ItemsSource = null;
  9. UserDataGrid.ItemsSource = UserDataGridCollection;
  10.  
  11. public class UserDataGridCategory : INotifyPropertyChanged
  12. {
  13. public event PropertyChangedEventHandler PropertyChanged;
  14. private int id;
  15. private string user, status;
  16.  
  17. public int ID
  18. {
  19. get { return id; }
  20. set { id = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ID")); }
  21. }
  22. public string User
  23. {
  24. get { return user; }
  25. set { user = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("User")); }
  26. }
  27. public string Status
  28. {
  29. get { return status; }
  30. set { status = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Status")); }
  31. }
  32. }
  33.  
  34. static class UserEngine
  35. {
  36. public static ObservableCollection<UserDataGridCategory> UserDataGridCollection { get; set; }
  37. public static object _lock = new object();
  38.  
  39. public static void RunEngine(DataGrid UserDataGrid)
  40. {
  41. UserDataGridCollection = new ObservableCollection<UserDataGridCategory>();
  42. BindingOperations.EnableCollectionSynchronization(UserDataGridCollection, _lock);
  43.  
  44. // Some other code
  45.  
  46. // Spawn thread to invoke dispatcher and do some other stuff
  47. }
  48. }
  49.  
  50. <DataGrid Name="UserDataGrid" x:FieldModifier="public" ItemsSource="{Binding UserDataGridCollection}" SelectedItem="{Binding SelectedRow, Mode=TwoWay}" Margin="10,16,22.6,215" AutoGenerateColumns="False" IsReadOnly="True">
  51. <DataGrid.Resources>
  52. <ContextMenu x:Key="RowMenu" Focusable="False"
  53. DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
  54. <MenuItem Header="View Log" Click="ViewLog" Focusable="False"/>
  55. </ContextMenu>
  56. </DataGrid.Resources>
  57. <DataGrid.RowStyle>
  58. <Style TargetType="DataGridRow" >
  59. <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
  60. </Style>
  61.  
  62. </DataGrid.RowStyle>
  63. <DataGrid.Columns>
  64. <DataGridTextColumn Header="ID #" Binding="{Binding ID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"/>
  65. <DataGridTextColumn Header="User" Binding="{Binding User, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="150"/>
  66. <DataGridTextColumn Header="Status" Binding="{Binding Status,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="250"/>
  67. </DataGrid.Columns>
  68. </DataGrid>
Add Comment
Please, Sign In to add comment