English 中文(简体)
名单 方框项目没有在妇女论坛获得复习?
原标题:ListBox item doesn t get refresh in WPF?
  • 时间:2010-05-25 03:31:15
  •  标签:
  • wpf
  • listbox

我有一个清单箱,有多个项目。 当每件物品被双重点击时,用户可以选择贴现(项目文本)。 现在,一旦更新该项目,我列入清单的项目就没有更新。

alt text

第一个窗口(有一个有箱子)位于主妇dow。 Xaml文档和第二扇窗位于EditTaskView.xaml(其中一人可以ed上物品文本)。

清单中显示物品的代码是:

主编:Windows.cs

公共静态孔观察组

    public void GetTask()
    {
        TaskList = new ObservableCollection<Task>
                           {
                               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;
    } 

显示清单的xaml代码:

<ListBox x:Name="lstBxTask" Style="{StaticResource ListBoxItems}" MouseDoubleClick="lstBxTask_MouseDoubleClick">
        <ListBox.ItemTemplate>              
            <DataTemplate>                   
                <StackPanel>
                    <Rectangle Style="{StaticResource LineBetweenListBox}"/>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Taskname}"  Style="{StaticResource TextInListBox}"/>
                        <Button Name="btnDelete" Style="{StaticResource DeleteButton}" Click="btnDelete_Click"/>                                                     
                    </StackPanel>
                </StackPanel>                   
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox> 
    <ToDoTask:EditTaskView x:Name="EditTask" Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="2" Visibility="Collapsed"/> 

Save button in TaskEditView.xaml do 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;

 }

工作队是可观察的Collection,但一旦你更新了该调查股的更新价值。 但似乎没有这样做。

什么是失踪的?

最佳回答

认为你可能有必要实施创新做法 任务类别发生变化。 这一接口提醒审计组,基本数据已发生变化,需要重新计算数据以更新意见。

问题回答

It s important to note that although the ObservableCollection class broadcasts information about changes to its elements, it doesn t know or care about changes to the properties of its elements. In other words, it doesn t watch for property change notification on the items within its collection. If you need to know if someone has changed a property of one of the items within the collection, you ll need to ensure that the items in the collection implement the INotifyPropertyChanged interface, and you ll need to manually attach property changed event handlers for those objects

http://msdn.microsoft.com/en-us/magazine/d252944.aspx“rel=“nofollow noreferer”http://msdn.microsoft.com/en-us/magazine/d252944.aspx

执行财产委员会更改的通知核对如下:http://msdn.microsoft.com/en-us/library/ms743695.aspx

这里是《劳动法》:

public class Task: INotifyPropertyChanged
    {
        //public string Taskname { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;
        private string _taskname;
        public Task(string value)
        {
            this._taskname = value;
        }
        public string Taskname
        {
            get { return _taskname; }
            set
            {
                _taskname = value;
                OnPropertyChanged("Taskname");
            }
        }
        private void OnPropertyChanged(string value)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(value));
            }
        }
    }

all the answers so far are very good,just for education purposes. have you tried to do

listbox.items.Refresh();

更新之后?





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签