我试图让 ListView 更改为我在 ObvservableCollection 中修改的任何值。
我目前正在使用它并将集合绑定到我的 ListView
private ObservableCollection<Task> _tasks = TaskInit.TaskCollection;
/// <summary>
/// Observable Collection to hold all tasks
/// </summary>
///
public ObservableCollection<Task> TasksCollection
{
get { return _tasks; }
set
{
_tasks = value;
NotifyPropertyChanged("TasksCollection");
}
}
问题是如果我要使用以下代码:
TaskInit.TasksCollection[2].TaskNumber = "hi";
该值仍将与以前的值相同,即使它应该已更改。
谁能指出我可能遇到的问题?
xaml 的第一行是:
<ListView SelectionMode="Single" ScrollViewer.CanContentScroll="True" x:Name="listTasks" Margin="0,0,0,35" Background="{x:Null}" BorderBrush="{x:Null}" ItemsSource="{Binding TasksCollection, Mode=TwoWay}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" FontFamily="Myriad Pro" Foreground="{x:Null}" IsSynchronizedWithCurrentItem="True">
任务类:
public class Task : INotifyPropertyChanged
{
/// <summary>
///
/// </summary>
public string Module { get; set; }
/// <summary>
///
/// </summary>
public string FirstValue { get; set; }
/// <summary>
///
/// </summary>
public string SecondValue { get; set; }
/// <summary>
///
/// </summary>
public string ThirdValue { get; set; }
/// <summary>
///
/// </summary>
public int Minutes { get; set; }
/// <summary>
///
/// </summary>
public string TaskNumber { get; set; }
/// <summary>
///
/// </summary>
public string Story1 { get; set; }
/// <summary>
///
/// </summary>
public string Story2 { get; set; }
/// <summary>
///
/// </summary>
public string Story3 { get; set; }
/// <summary>
///
/// </summary>
public string NetworkAdapter { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}