gpt4 book ai didi

silverlight - 使用 MVVM 隐藏 Silverlight DataGrid

转载 作者:行者123 更新时间:2023-12-03 10:30:05 24 4
gpt4 key购买 nike

如何使用 MVVM 绑定(bind)数据网格可见性,以便在没有数据的情况下将 DataGrid 的可见性设置为 Collapsed , 这样代码就可以重用了。
谢谢。

最佳答案

在 ViewModel 中公开属性,如

// In setter consider INotifyPropertyChanged 
public bool IsDataAvailable
{
get; set;
}

在 XAML 中:
<DataGrid Visibility="{Binding IsDataAvailable, 
Converter={StaticResource BooleanToVisibilityConverter}}" />

一些有用的链接:
  • How to declare and use BooleanToVisibilityConverter in my View
  • Good examples of the BooleanToVisibilityConverter implementation
  • WPF MVVM INotifyPropertyChanged Implementation - Model or ViewModel
  • 关于silverlight - 使用 MVVM 隐藏 Silverlight DataGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054402/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com