当前位置: 首页 > 编程语言 > C#

打开和关闭WPFDataGrid背景图片?Share

时间:2023-04-11 10:29:51 C#

打开和关闭WPFDataGrid背景图像?我有一个DataGrid,我想在它为空时显示背景图像。我希望图像在填充DataGrid时消失,并在再次清除DataGrid时重新出现。这可以通过XAML或C#实现吗?如果(myDataGridView.Rows.Count==0){dataGrid.Background=newImageBrush(“exampleImage.png”);}else{//它不为空}如果您使用MVVM设计模式hide,通常应避免使用代码。在XAML中执行此操作非常简单:将一个Image元素放在数据网格的顶部(将两者都放在一个Grid中,然后将Image放在DataGrid的下面),然后使用新的转换器将要设置的Image的Visibility属性绑定到DataGrid的Items.Count属性:转换器如下所示:返回计数==0?Visibility.Visible:Visibility.Collapsed;我假设您正在使用WPF,使用Windows窗体将非常困难。以上就是C#学习教程:打开和关闭WPFDataGrid背景图片?如果分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注—System.Windows.Controls.DataGriddataGrid=newSystem.Windows.Controls.DataGrid();publicvoidInitialize(){dataGrid.Loaded+=newSystem.Windows.RoutedEventHandler(dataGrid_Loaded);dataGrid.Unloaded+=newSystem.Windows.RoutedEventHandler(dataGrid_Unloaded);//立即显示图像。this.dataGrid_Unloaded(null,null);}voiddataGrid_Unloaded(objectsender,System.Windows.RoutedEventArgse){//在这里提供一些图像。dataGrid.Background=newSystem.Windows.Media.ImageBrush();}voiddataGrid_Loaded(objectsender,System.Windows.RoutedEventArgse){dataGrid.Background=System.Windows.Media.Brushes.Gray;}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: