wpf DataGrid列中绑定图片删除
2013-03-25 16:25
381 查看
wpf界面
<Windowx:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MainWindw.CommHelper">
c#代码
在按钮中删除绑定的图片时候不会报错
该图片不能删除,因为别的进程正在使用它
如果程序报错
WPF,bindingtoanimagewithoutfileaccessexceptions(绑定的图像文件访问异常)
可能是该文件不是图像格式文件造成。文件格式必须是png,jpg之类的图像格式才行。
<Windowx:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MainWindw.CommHelper">
<DataGridTemplateColumnHeader="图片"MinWidth="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ImageHeight="100"Width="100"Source="{BindingPath=FilePath,Converter={StaticResourceImagePathConverter}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<Window.Resources>
<local:ConvertTextToImagex:Key="ImagePathConverter"/>
</Window.Resources>
c#代码
publicclassConvertTextToImage:IValueConverter
{
#regionIValueConverterMembers
publicobjectConvert(objectvalue,TypetargetType,objectparameter,System.Globalization.CultureInfoculture)
{
if(value==null)
returnnull;
if(!string.IsNullOrEmpty(value.ToString()))
{
BitmapImagebi=newBitmapImage();
bi.BeginInit();
bi.UriSource=newUri(value.ToString(),UriKind.RelativeOrAbsolute);
bi.CacheOption=BitmapCacheOption.OnLoad;
bi.EndInit();
returnbi;
}
returnnull;
}
publicobjectConvertBack(objectvalue,TypetargetType,objectparameter,System.Globalization.CultureInfoculture)
{
thrownewNotImplementedException();
}
#endregion
}
在按钮中删除绑定的图片时候不会报错
该图片不能删除,因为别的进程正在使用它
如果程序报错
WPF,bindingtoanimagewithoutfileaccessexceptions(绑定的图像文件访问异常)
可能是该文件不是图像格式文件造成。文件格式必须是png,jpg之类的图像格式才行。
相关文章推荐
- Wpf DataGrid 数据绑定 排序 删除
- wpf datagrid绑定数据中每行都有删除按钮
- Wpf DataGrid 数据绑定 排序 删除
- wpf datagrid 绑定图片列 资源回收问题
- WPF DataGrid绑定及列居中
- WPF中DataGrid使用自定义列绑定数据
- WPF中DataGrid的ComboBox的简单绑定方式(绝对简单)
- WPF DataGrid 数据绑定
- WPF DataGrid 绑定DataSet数据 自动生成行号
- WPF dataGrid下的ComboBox的绑定
- WPF DataGrid列设置为TextBox控件的相关绑定
- WPF DataGrid 数据绑定、样式、分页、增删改查,连接Access数据库
- WPF,DataGrid数据绑定
- wpf中的datagrid中如何显示图片
- 【转】解决WPF图片模糊最佳方法(绑定PixelWidth与PixelHeight)
- wpf 右键datagrid删除datatable
- WPF 控件DataGrid绑定
- WPF 绑定实例之 LISTBOX显示 图片列表
- WPF入门(四)-WPF+LINQ实现数据绑定、交互及简单datagrid样式
- 关于wpf DataGrid 的增加删除行操作