C# 使用图像刷新ListView项';s源绑定到属性

C# 使用图像刷新ListView项';s源绑定到属性,c#,listview,windows-runtime,windows-phone-8.1,C#,Listview,Windows Runtime,Windows Phone 8.1,刷新listview数据时出现问题。它不会更新,除非我调用: List.ItemsSource = null; List.ItemsSource = listviewSource; 这是可行的,但不好看(屏幕闪烁),所以我想使用,正如人们所建议的,INotifyPropertyChanged public class Class1 : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyCh

刷新listview数据时出现问题。它不会更新,除非我调用:

List.ItemsSource = null;
List.ItemsSource = listviewSource;
这是可行的,但不好看(屏幕闪烁),所以我想使用,正如人们所建议的,INotifyPropertyChanged

public class Class1 : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }

    ...
}

public class Class2 : Class1
{

    private string ImgSource;

    public string imgSource
    {
        get { return this.ImgSource; }
        set
        {
            this.ImgSource = value;
            NotifyPropertyChanged("imgSource");
        }
    }

    ....
}
我的listviewSource是ObservableCollection,其中Class2实现Class1,Class1实现INotifyPropertyChanged

public class Class1 : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }

    ...
}

public class Class2 : Class1
{

    private string ImgSource;

    public string imgSource
    {
        get { return this.ImgSource; }
        set
        {
            this.ImgSource = value;
            NotifyPropertyChanged("imgSource");
        }
    }

    ....
}
imgSource绑定到ListView,但当它更改时,不会发生任何事情。。。我做错什么了吗

XAML标记

<ListView x:Name="List" Width="400" HorizontalAlignment="Center" Loaded="List_Loaded">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Top"/>
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="VerticalAlignment" Value="Top"/>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Tag="{Binding number}" Background="#FF0E1D23" Margin="0,5" >
                        <Image Margin="339,10,23,13" Source="{Binding imgSource}"/>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

似乎
图像
默认为
一次性

将其显式更改为单向

Source="{Binding imgSource, Mode = OneWay}"

老实说,我不确定
源代码
绑定是否以这种方式与
图像
一起工作。您可以尝试将其绑定更改为单向
(默认情况下可能是一次性)。另外,为了确保我正确理解问题,您更改了
imgSource
,但相应的图像没有更改?或者更改集合(从
可观察集合中添加、删除
Class2
)但是listView中没有任何变化?我更改了ImgSource,但图像保持不变-但是当我调用源为null,然后再次设置时-然后图像发生了变化,使其正常工作:D thansb但即使InotifyProperty发生了变化,屏幕仍有一点闪烁,更小,但仍然是:)@JakubWisniewski不幸的是,这就是图像更改如何与绑定一起工作。也许您可以在与旧图像相同的位置(就在下面)创建已更改的不可见图像,然后删除旧图像。但是它需要相当多的UI代码,而且,我认为,用一些布局来实现会有问题。也许网络上有一些准则可以处理这种轻微的尴尬效应。此外,您还可以尝试调整图像的大小(图像越大,滞后时间越长)。