Datagrid 我无法刷新字段

Datagrid I Can't refresh field

我无法刷新数据网格中的字段。

这是我的 DataGrid:

<DataGrid ItemsSource="{Binding Dati_Viaggio}"
          SelectedItem="{Binding SelectDati_Viaggio}" 
          Style="{DynamicResource ST_DataGrid}" 
          CellStyle="{DynamicResource St_DataGridCellStyle}"
          SelectionMode="Single"  Name="Dg_Dati" IsReadOnly="True"
          RowDetailsVisibilityMode="VisibleWhenSelected">

这是 DataGrid 中我要刷新的字段

<DataGridTextColumn x:Name="col_NumOrd" Binding="{Binding Path=NumOrd}"
                    Header="Num. Ord." Width="150"/>

这是 属性:

public ObservableCollection<Model_Ricerca_Dati_Viaggio> Dati_Viaggio { get; set; }
private Model_Ricerca_Dati_Viaggio _SelectDati_Viaggio;
public Model_Ricerca_Dati_Viaggio SelectDati_Viaggio
{
    get { return _SelectDati_Viaggio; }
    set
    {
        _SelectDati_Viaggio = value;
        OnPropertyChanged("SelectDati_Viaggio");
    }
}

为什么我写这段代码 DataGrid 不刷新字段?

SelectDati_Viaggio.NumOrd= "abcabc";
OnPropertyChanged("SelectDati_Viaggio");

谢谢。

我认为:

<DataGridTextColumn x:Name="col_NumOrd" Binding="{Binding Path=NumOrd}"/>

您绑定到 NumOrd 但此处:

SelectDati_Viaggio.NumOrd= "abcabc";
OnPropertyChanged("SelectDati_Viaggio");

正在通知SelectDati_Viaggio,您需要通知NumOrd

SelectDati_Viaggio.NumOrd= "abcabc";
OnPropertyChanged("NumOrd");

比您的控件知道 属性 更新和刷新

编辑: 编辑你的 SelectDati_Viaggio class

private string numOrd;
public string NumOrd 
{ 
   get { return numOrd; } 
   set { numOrd = value; OnPropertyChanged("NumOrd"); }
}

希望有所帮助!

尝试通过重新声明和重新查询集合来刷新绑定并初始化到数据网格,在搜索了几天的解决方案后尝试了这个。如果你明白了。

server = mongoClient.GetServer();
database = server.GetDatabase("facultyDataAndSchedule");
collection = database.GetCollection<facultyData>("faculty");
var query = collection.FindAllAs<facultyData>()
    .SetFields(Fields.Include("facultyID", "term", "acadYear", "age",
    "program", "lastName", "firstName", "middleName", "dateOfBirth",
    "rank", "yearsOfTeachingS", "yearsOfTeachingO", "status", "services"));
// List<facultyData> resultList = query.ToList<facultyData>();
resultBinding = new ObservableCollection<facultyData>(query);
facultyDataGrid.ItemsSource = resultBinding;
try
{
    try
    {
        var entity = new facultyData
        {
            facultyID = facultyID_Textbox.Text.ToString(),
            term = termComboBox.SelectedItem.ToString(),
            age = int.Parse(age_TextBox.Text),
            acadYear = "2014-2015",
            firstName = firstName_TextBox.Text.ToString(),
            lastName = lastName_TextBox.Text.ToString(),
            middleName = middleName_TextBox.Text.ToString(),
            dateOfBirth = dateOfBirth_TextBox.Text.ToString(),
            program = "progra",
            rank = "gegs",
            services = "gegsg",
            status = "geh",
            yearsOfTeachingO = 1,
            yearsOfTeachingS = 1
        };
        collection.Insert(entity);
    }
    catch (FormatException ex)
    {
        Console.WriteLine(ex);
    }
}
catch (MongoConnectionException ex)
{
    Console.WriteLine(ex);
}
var query1 = collection.FindAllAs<facultyData>()
    .SetFields(Fields.Include("facultyID", "term", "acadYear", "age",
    "program", "lastName", "firstName", "middleName", "dateOfBirth",
    "rank", "yearsOfTeachingS", "yearsOfTeachingO", "status", "services"));
// List<facultyData> resultList = query.ToList<facultyData>();
resultBinding = new ObservableCollection<facultyData>(query1);
facultyDataGrid.ItemsSource = resultBinding;