无法在WPF中绑定ListView

时间:2018-06-21 11:36:13

标签: c# wpf listview binding

我想吸引图像用户并在ListView WPF / Csharp中显示

我使用 Binding 来获取值。

这是我的代码:

xaml:

            <ListView ItemsSource="{Binding InstaMedia}" 
              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
        >
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <Image Stretch="Fill" Source="{Binding [0].Images[0].URI}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListView>

和C#:

 public partial class ProfileUserPage : INotifyPropertyChanged
{

    public ProfileUserPage()
    {
        InitializeComponent();
    }



    private List<InstaMedia> _instsmedia;
    public List<InstaMedia> InstaMedia
    {
        get { return _instsmedia; }
        set
        {
            if (_instsmedia != value)
            {
                _instsmedia = value;
                OnPropertyChanged();
            }
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged([CallerMemberName] string propertyNmae = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyNmae));
    }

    private async void Page_LoadedAsync(object sender, RoutedEventArgs e)
    {
        var GetPost = await user.GetUserMediaAsync(...); //this takes about 5 seconds for get images
        _instsmedia = GetPost.Value;         
    }

图像用户可用于:

   _instsmedia[X].Images[X].URI

但是这不起作用,并且在我的ListView中不显示任何内容。我该如何解决?

请帮助我。

0 个答案:

没有答案