I am deleting a row in the grid and when the user clicks the delete button the property IsDeleted
in the collection is changed to true
and so the filter in .xaml page binds the property to the telerik grid
.
我正在删除网格中的一行,当用户单击删除按钮时,集合中的属性IsDeleted将更改为true,因此.xaml页面中的过滤器会将属性绑定到telerik网格。
//Code
//码
Filter:
过滤:
<telerik:RadGridView.FilterDescriptors>
<telerik:FilterDescriptor Member="IsDeleted" Operator="IsEqualTo" Value="False"/>
</telerik:RadGridView.FilterDescriptors>
ViewModel:
视图模型:
if (this.IsNPISItemSelected && MessageBox.Show("Are you sure that you want to delete the selected npis item?", "Delete NPIS Item", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
this.SelectedNPISItem.IsDeleted = true;
}
Binding GridView:
绑定GridView:
<telerik:RadGridView x:Name="grdNPISItem" ItemsSource="{Binding NPISItemsCollection, Mode=TwoWay}" AutoGenerateColumns="False" SelectedItem="{Binding SelectedNPISItem, Mode=TwoWay, Source={StaticResource NPISViewModel}}"
HorizontalAlignment="Stretch" telerik:StyleManager.Theme="Windows8"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}, Path=ActualWidth, Converter={StaticResource PercentageConverter}, ConverterParameter=0.98}"
GridLinesVisibility="Both">
But now, when i delete the row its still showing. The thing is if the property is false the row should not be shown in the grid.
但现在,当我删除它仍然显示的行。问题是如果属性为false,则行不应显示在网格中。
I guess the grid is not refreshing.
我猜网格并不令人耳目一新。
Where i'm wrong?
哪里我错了?
1 个解决方案
#1
1
Apparently, RadGridView does not treat property change as reason to update filters. You can test and see that if you update the value via grid itself, then filtering takes place normally because proper grid edit procedure is done.
显然,RadGridView不会将属性更改视为更新过滤器的原因。您可以测试并查看如果您通过网格本身更新值,则正常进行过滤,因为正确的网格编辑过程已完成。
Simple solution can be to raise some custom event in ViewModel to notify the View that filters should be updated:
简单的解决方案是在ViewModel中引发一些自定义事件,以通知View应该更新过滤器:
grdNPISItem.FilterDescriptors.Reset();
But I think that it could be better to move that logic to ViewModel and make a collection with just existing values and bind it to the grid:
但我认为将逻辑移动到ViewModel并使用现有值创建集合并将其绑定到网格可能会更好:
public IEnumerable<NPISItem> ExistingNPISItemsCollection
{
get
{
return NPISItemsCollection == null
? Enumerable.Empty<NPISItem>()
: NPISItemsCollection .Where(d => !d.IsDeleted);
}
}
Then when you change IsDeleted
property you just call PropertyChanged for this collection and grid will pick it up. This also allows to keep grid column filtering so user can work with shown items as he likes.
然后,当您更改IsDeleted属性时,只需为此集合调用PropertyChanged,网格就会将其拾取。这还允许保持网格列过滤,以便用户可以随意使用所显示的项目。
The null check here is in case collection`s not initialized yet when binding takes place, so you can either remove it if you don`t need it or call PropertyChanged for this collection in NPISItemsCollection
setter.
这里的空检查是在绑定发生时尚未初始化集合的情况下,因此如果您不需要它,可以将其删除,或者在NPISItemsCollection setter中为此集合调用PropertyChanged。
#1
1
Apparently, RadGridView does not treat property change as reason to update filters. You can test and see that if you update the value via grid itself, then filtering takes place normally because proper grid edit procedure is done.
显然,RadGridView不会将属性更改视为更新过滤器的原因。您可以测试并查看如果您通过网格本身更新值,则正常进行过滤,因为正确的网格编辑过程已完成。
Simple solution can be to raise some custom event in ViewModel to notify the View that filters should be updated:
简单的解决方案是在ViewModel中引发一些自定义事件,以通知View应该更新过滤器:
grdNPISItem.FilterDescriptors.Reset();
But I think that it could be better to move that logic to ViewModel and make a collection with just existing values and bind it to the grid:
但我认为将逻辑移动到ViewModel并使用现有值创建集合并将其绑定到网格可能会更好:
public IEnumerable<NPISItem> ExistingNPISItemsCollection
{
get
{
return NPISItemsCollection == null
? Enumerable.Empty<NPISItem>()
: NPISItemsCollection .Where(d => !d.IsDeleted);
}
}
Then when you change IsDeleted
property you just call PropertyChanged for this collection and grid will pick it up. This also allows to keep grid column filtering so user can work with shown items as he likes.
然后,当您更改IsDeleted属性时,只需为此集合调用PropertyChanged,网格就会将其拾取。这还允许保持网格列过滤,以便用户可以随意使用所显示的项目。
The null check here is in case collection`s not initialized yet when binding takes place, so you can either remove it if you don`t need it or call PropertyChanged for this collection in NPISItemsCollection
setter.
这里的空检查是在绑定发生时尚未初始化集合的情况下,因此如果您不需要它,可以将其删除,或者在NPISItemsCollection setter中为此集合调用PropertyChanged。