Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF列表框项位图图像更新_C#_Wpf_Xaml - Fatal编程技术网

C# WPF列表框项位图图像更新

C# WPF列表框项位图图像更新,c#,wpf,xaml,C#,Wpf,Xaml,我用图像缩略图查看器创建了一个图像编辑软件。我有一个功能,这是旋转图像,用户选择一张照片,并点击按钮。问题是我不想刷新所有的列表框。所以这个代码: ImageListbox.Items.Refresh(); //Very slow if i have more than 100 imgs. 我想要一个INotifyPropertyChanged仅用于BitmapImage XAML: C# 公共类reportageItems:ObservableCollection { public re

我用图像缩略图查看器创建了一个图像编辑软件。我有一个功能,这是旋转图像,用户选择一张照片,并点击按钮。问题是我不想刷新所有的
列表框。所以这个代码:

ImageListbox.Items.Refresh(); //Very slow if i have more than 100 imgs.
我想要一个
INotifyPropertyChanged
仅用于
BitmapImage

XAML:


C#

公共类reportageItems:ObservableCollection
{
public reportagements(){}
}
公共类ReportageItem:INotifyPropertyChanged
{
//我这里有两个以上的属性,对于这个例子来说不是必需的。
私有字符串_ImgName;
公共字符串ImgName
{
获取{返回此。\ ImgName;}
设置
{
if(this.\u ImgName!=值)
{
这个。_ImgName=值;
本条。NotifyPropertyChanged(“ImgName”);
}
}
}
公共事件属性更改事件处理程序属性更改;
public void NotifyPropertyChanged(字符串propName)
{
if(this.PropertyChanged!=null)
this.PropertyChanged(this,newpropertyChangedEventArgs(propName));
}
}
//在Btn点击事件中,我有:
List changeItem=ImageListbox.Items.OfType()。其中(x=>x.CheckBox.ToList();
foreach(Model.Where(x=>x.ImgPath==changeItem.First().ImgPath)中的var项)
{
item.CheckBox=false;//有效
item.ImgName=“新名称”;//有效
item.ImgPath=@“C:\Programa Provas\Destino\Performance15\Uteis\Thumb\1.JPG”;//不起作用。。。
}

图像
元素的
属性直接绑定到源属性:

<Image Margin="5,5,5,5" Height="300" Width="280" VerticalAlignment="Top" Source="{Binding Path=ImgName}"/>

…或使用转换器创建并返回
位图图像

public class ReportagemItems : ObservableCollection<ReportagemItem>
{
    public ReportagemItems() { }
}

public class ReportagemItem : INotifyPropertyChanged
{
    //i have more 2 properties here, not necessary for this example.

    private string _ImgName;
    public string ImgName
    {
        get { return this._ImgName; }
        set
        {
            if (this._ImgName != value)
            {
                this._ImgName = value;
                this.NotifyPropertyChanged("ImgName");
            }
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyPropertyChanged(string propName)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
}

//in Btn Click event i have:

List<ReportagemItem> changeItem = ImageListbox.Items.OfType<ReportagemItem>().Where(x => x.CheckBox).ToList();

foreach (var item in Model.Where(x => x.ImgPath == changeItem.First().ImgPath))
{
    item.CheckBox = false; //WORKS
    item.ImgName = "New Name"; //WORKS
    item.ImgPath = @"C:\Programa Provas\Destino\Performance15\Uteis\Thumb\1.JPG"; //DOESNT WORK...
}
<Image Margin="5,5,5,5" Height="300" Width="280" VerticalAlignment="Top" Source="{Binding Path=ImgName}"/>