Where is the WPF DataGrid DataBindingComplete event?

I need to take some action (for example, to make some cells based only on some other cells) after the data overwrite is complete. In WinForm DataGridView, I used this in the DataBindingComplete event. However, I could not find such an event in the WPF DataGrid. What else can I use?

+5
source share
6 answers

This is what I found out: the DataContextChanged event is the right event to use. The only problem is that the datagrid is not quite ready for use in my code inside this event. However, it works fine if I use Dispatcher.BeginInvoke as follows:

Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => DoSomethingWithGrid()));

- , ?

, WPF DataGrid Dispatcher , . ?

+6

DataContextChanged.

+1

, , datagrid , .

+1

, (DataGrid.Initialized, DataContextChanged, AddingNewItem, RowLoaded ..) BeginInvoke, . :

Loaded

, , .

private void SubjectsList_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => ColorMyRows()));
}

CollorMyRows tihs:

private void ColorMyRows()
{
    DataGridRow row = null;
    for (int i = 0; i < SubjectsList.Items.Count; i++)
    {
        // get one row
        row = SubjectsList.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
        if (myConditionIsFulfilled)
        {
            row.Background = Brushes.PaleGoldenrod; // black'n gold baby
            row.ToolTip = "This item fulfills the condition.";
        }
        else
        {
            row.Background = Brushes.PaleGreen;
            row.ToolTip = "This item does not.";
        }
    }
}

. ObservableCollection, DataGrid, ( DataGrid) :)

+1

readonly , . , , , , DataGrid, , ,

public class Model : INotifyPropertyChanged
    {
public bool IsChecked
        {
            get { return isChecked; }
            set
            {
                isChecked = value;
                RaisePropertyChanged("IsChecked");
                RaisePropertyChanged("Visibilty");
            }
        }
public Visibility Visibilty
        {
            get
            {
                return IsChecked ? Visibility.Visible : Visibility.Hidden;
            }
        }
}

datagrid, IsChecked Property , , . , .

0

You can declare BackgroundWorker and try to populate the GridView in the DoWork event and write your code in the RunWorkerCompleted event

0
source

All Articles