5e3*_*0fc 7 wpf entity-framework
我有一个WPF DataGrid绑定到Entity Framework父EF对象内的对象集合.有点像:
<DataGrid ItemsSource="{Binding SelectedCustomer.Orders}" />
Run Code Online (Sandbox Code Playgroud)
现在,当我想"删除"订单时,我不想将其从数据源中删除,我只是想将其IsDeleted属性设置为true,以便保留数据.
我的问题是:DataGrid如果它的IsDeleted属性是真的,我怎么能让我跳过一行?我真的想使用绑定而不是代码隐藏.像这样的东西会很精彩:
<DataGrid ItemsSource="{Binding SelectedCustomer.Orders}" RowVisibilityPath="IsDeleted" />
Run Code Online (Sandbox Code Playgroud)
有点像DisplayMemberPath.我意识到我需要转换状态IsDeleted,但这是一个不同的主题.
有任何想法吗?
H.B*_*.B. 23
除了使用上面提到的CollectionView之外,您还可以通过RowStyle执行此操作:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDeleted}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Run Code Online (Sandbox Code Playgroud)
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Visibility" Value="{Binding IsDeleted, Converter={StaticResource BoolToVisibility}}"/>
</Style>
</DataGrid.RowStyle>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11763 次 |
| 最近记录: |