【问题标题】:Detect when DataGrid have and dont have content检测 DataGrid 何时有内容和没有内容
【发布时间】:2014-07-24 01:43:43
【问题描述】:

当它有一个内容时,我想将一个按钮 IsEnabled 属性绑定到 DataGrid 属性/事件。 DataGrid 的 Item Source 是一个 Observable 集合,但由于我实现了 Filtering,所以显示的内容可能与 ItemSource 集合不同。

当 View 为空或不为空时是否会触发 DataGrid 的事件或属性?

【问题讨论】:

  • 即使你使用了 Observable 集合并实现了 Filtering,你也可以得到集合的计数。用 Button 的 IsEnabled 属性绑定它。

标签: wpf wpfdatagrid icollectionview


【解决方案1】:

可以使用 DataGrid 的基类 ItemsControl 中的 HasItems 属性制作一个简单的示例

HasItems 只计算任何过滤器后可显示的行数

<StackPanel>
    <DataGrid x:Name="dGrid">
        an item
    </DataGrid>
    <Button Content="a button"
            IsEnabled="{Binding HasItems,ElementName=dGrid}" />
</StackPanel>

因此 DataGrid 中的 HasItems 将确定按钮是否启用

【讨论】:

    猜你喜欢
    • 2014-10-22
    • 2021-10-24
    • 1970-01-01
    • 2012-02-18
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多