rowspan不显示 wpf,在WPF中ListBox项没有刷新?

I have a listbox which has couple of items. When double clicked on each item, the user get option to edit item (text of item). Now once i update the item, my item in listbox doesn't get updated.

KcZ84.png

The first window (one which has listbox) is in MainWindow.xaml file and second window is in EditTaskView.xaml(one which let's edit the items text) file.

The code that displays items in lists is:

Main.Windows.cs

public static ObservableCollection TaskList;

public void GetTask()

{

TaskList = new ObservableCollection

{

new Task("Task1"),

new Task("Task2"),

new Task("Task3"),

new Task("Task4")

};

lstBxTask.ItemsSource = TaskList;

}

private void lstBxTask_MouseDoubleClick(object sender, MouseButtonEventArgs e)

{

var selectedTask = (Task)lstBxTask.SelectedItem;

EditTask.txtBxEditedText.Text = selectedTask.Taskname;

EditTask.PreviousTaskText = selectedTask.Taskname;

EditTask.Visibility = Visibility.Visible;

}

The xaml code that displays the list:

The Save button in TaskEditView.xaml does this:

public string PreviousTaskText { get; set; }

private void btnSaveEditedText_Click(object sender, RoutedEventArgs e)

{

foreach (var t in MainWindow.TaskList)

{

if (t.Taskname == PreviousTaskText)

{

t.Taskname = txtBxEditedText.Text;

}

}

Visibility = Visibility.Collapsed;

}

TaskList is the ObservableCollection, and i though once you update the value the UI gets refreshed. But doesn't seem to work that way.

What am i missing?

解决方案

Looks like you may need to implement INotifyPropertyChanged in your Task class. This interface alerts the UI that underlying data has changed and it needs to repull the data to update the view.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值