English 中文(简体)
wpf 数据网格刷新, 没有通知更改@ info: tooltip
原标题:wpf datagrid refresh without INotifiedChanges

我用Wpf和.xaml.cs的代码输入数据格

List<TaskHeader> taskHeaders;
//initialization of taskHeaders
taskDataGrid.ItemsSource = taskHeaders;

点击刷新按钮后, 我需要更新任务负责人对任务 DataGrid 视图的更改, 但我无法在不执行可观察的集合的情况下找到路 。 taskDataGrid. items. rerefresh (); 无效 。

taskDataGrid.ItemsSource = null;
taskDataGrid.ItemsSource = taskHeaders;
taskDataGrid.Items.Refresh();

is not working too any idea? please help

问题回答

尝试

CollectionViewSource.GetDefaultView(taskHeaders).Refresh();

我测试了这个和这个作品:

我的XAML:

<Window x:Class="WpfApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<DockPanel>
    <Button DockPanel.Dock="Bottom" Content="Change list and refresh grid" Click="OnRefreshButtonClicked"/>
    <DataGrid x:Name="taskDataGrid"/>
</DockPanel>

我的代码后面写着:

using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;

namespace WpfApplication
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var taskHeaders = new List<TaskHeader>();
            for (int i = 0; i < 10; ++i)
                taskHeaders.Add(new TaskHeader() { Property = "Property " + i });

            this.taskDataGrid.ItemsSource = taskHeaders;
        }

        private void OnRefreshButtonClicked(object sender, RoutedEventArgs e)
        {
            var taskHeaders = (List<TaskHeader>)this.taskDataGrid.ItemsSource;

            // Make changes on taskHeaders by removing first item.
            taskHeaders.RemoveAt(0);

            CollectionViewSource.GetDefaultView(taskHeaders).Refresh();
        }
    }
}

和我的假任务负责人班:

namespace WpfApplication
{
    public class TaskHeader
    {
        public string Property { get; set; }
    }
}

而不是约束整个列表, 请尝试这一个(实际上我不知道你的逻辑如何, 但也许能帮上忙) 。

任务列头值是一个任务列头对象。

titleDataGrid. items.Add(任务负责人)





相关问题
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 ...

热门标签