如何使用UWP和MVVM Light刷新Telerik数据网格 [英] How to refresh a Telerik datagrid using UWP and MVVM Light

查看:139
本文介绍了如何使用UWP和MVVM Light刷新Telerik数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的光临.

单击刷新"按钮时,无法刷新Telerik网格.换句话说,如果用户更改数据并决定不保存数据,则单击刷新"按钮应将原始值重新加载到网格中.

I am having trouble refreshing a Telerik grid when the Refresh button is clicked. In other words, if the user changes the data and decides not to save it, clicking the refresh button should reload the grid with the original values.

这是刷新视图"中的XAML:

Here is my XAML in the View for the Refresh:

<Button Content="Refresh" Grid.Row="1" Margin="92,5,0,11" Command="{x:Bind ViewModel.RefreshDataCommand}"/>

这是我在表格视图中的XAML:

Here is my XAML in the View for the Grid:

<tg:RadDataGrid ColumnDataOperationsMode="Flyout"  x:Name="grid" ItemsSource="{Binding Source,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedItem="{x:Bind ViewModel.CurrentUserData, Mode=TwoWay}" UserEditMode="Inline"  Grid.ColumnSpan="4" Grid.Row="1" AutoGenerateColumns="False">

请注意,在上面的代码中,网格已绑定到ViewModel中的Source属性.这是ViewModel中的bound属性:

Notice that in the above code the grid is bound to the Source property in the ViewModel. Here is the bound property in the ViewModel:

public ObservableCollection<UserData> Source
    {
        get
        {
            try
            {
                udCol = GetUserData(FileName).Result;
                return udCol;
            }
            catch (AggregateException ex)
            {

                return null;
            }

        }
        set
        {
            udCol = value;
        }
    }

导航到页面时,上述属性会自动将数据加载到网格中.

The above property automatically loads the data in the grid when the page is navigated to.

这是刷新"按钮绑定到的功能:

Here is the function that the Refresh button is bound to:

private void RefreshDataCommandAction()
    {
        udCol[0].Name = "test1";
        CurrentUserData = udCol[0];
        Source = udCol;
        RaisePropertyChanged("Source");

    }

我正在尝试使用上述功能,这就是为什么代码看起来多余,但是无论我做什么,该功能中的新分配都不会更新UI.理想情况下,用户将更新用户界面中的单元格,然后单击刷新"以返回原始状态或仅重新加载数据. ViewModel继承了包含INotifyPropertyChanged的ViewModelBase,我认为当属性更改时,这足以将更改传播到UI.我不想仅仅为了更新UI而破坏MVVM模式.

I was experimenting in the above function, that is why the code looks redundant but no matter what I do the new assignment in this function does not update the UI. Ideally, the user will update the cell in the UI and click Refresh to go back to original or just reload the data. The ViewModel inherits ViewModelBase which contains INotifyPropertyChanged and I thought that that should be enough to propagate the changes to the UI when the property is changed. I don't want to break the MVVM pattern just to update the UI.

我非常感谢您的帮助.提前非常感谢!!!

I would really appreciate some help. Thanks a lot in advance!!!

我将视图"中的XAML更改为此,因为它破坏了我的ADD功能:

I changed my XAML in the View back to this because it broke my ADD functionality:

<tg:RadDataGrid ColumnDataOperationsMode="Flyout"  x:Name="grid" ItemsSource="{x:Bind ViewModel.Source}" SelectedItem="{x:Bind ViewModel.CurrentUserData, Mode=TwoWay}" UserEditMode="Inline"  Grid.ColumnSpan="4" Grid.Row="1" AutoGenerateColumns="False">

推荐答案

源未实现更改通知,因此UI无法知道您分配了其他实例.

Source does not implement Change Notification, so the UI has no way of knowing you assigned a different instance.

在MVVM中绑定任何形式的列表时,需要更改通知的三个部分:

When binding any form of list in MVVM, 3 parts need change notification:

  • 在(源)上公开列表的属性
  • 列表本身(可观察的集合负责此工作)
  • 您要公开的类型的每个属性(UserData的每个属性)

这篇关于如何使用UWP和MVVM Light刷新Telerik数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆