Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserDataGrid.Dispatcher.BeginInvoke(new Action(() =>
- {
- UserDataGridCollection[m_iID].Status = Log;
- UserDataGridCollection[m_iID].ID = m_iID;
- UserDataGridCollection[m_iID].User = m_sUser;
- }
- UserDataGrid.ItemsSource = null;
- UserDataGrid.ItemsSource = UserDataGridCollection;
- public class UserDataGridCategory : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private int id;
- private string user, status;
- public int ID
- {
- get { return id; }
- set { id = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ID")); }
- }
- public string User
- {
- get { return user; }
- set { user = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("User")); }
- }
- public string Status
- {
- get { return status; }
- set { status = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Status")); }
- }
- }
- static class UserEngine
- {
- public static ObservableCollection<UserDataGridCategory> UserDataGridCollection { get; set; }
- public static object _lock = new object();
- public static void RunEngine(DataGrid UserDataGrid)
- {
- UserDataGridCollection = new ObservableCollection<UserDataGridCategory>();
- BindingOperations.EnableCollectionSynchronization(UserDataGridCollection, _lock);
- // Some other code
- // Spawn thread to invoke dispatcher and do some other stuff
- }
- }
- <DataGrid Name="UserDataGrid" x:FieldModifier="public" ItemsSource="{Binding UserDataGridCollection}" SelectedItem="{Binding SelectedRow, Mode=TwoWay}" Margin="10,16,22.6,215" AutoGenerateColumns="False" IsReadOnly="True">
- <DataGrid.Resources>
- <ContextMenu x:Key="RowMenu" Focusable="False"
- DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
- <MenuItem Header="View Log" Click="ViewLog" Focusable="False"/>
- </ContextMenu>
- </DataGrid.Resources>
- <DataGrid.RowStyle>
- <Style TargetType="DataGridRow" >
- <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
- </Style>
- </DataGrid.RowStyle>
- <DataGrid.Columns>
- <DataGridTextColumn Header="ID #" Binding="{Binding ID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"/>
- <DataGridTextColumn Header="User" Binding="{Binding User, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="150"/>
- <DataGridTextColumn Header="Status" Binding="{Binding Status,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="250"/>
- </DataGrid.Columns>
- </DataGrid>
Add Comment
Please, Sign In to add comment