我尝试在现有的stackpanel中创建一个进度如下
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Height="150" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Vertical" Height="150" Width="192" >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Height="108" Width="192" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Vertical">
<ProgressRing IsActive="{Binding IsActive}" Height="15" Width="15" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Vertical" >
<TextBlock Text="{Binding Name}" TextAlignment="Center" Height="22" Width="192" Foreground="White" FontFamily="Assets/GothamLight.ttf#GothamLight"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我有一个可观察的项目集合如下
public class MyListItem
{
public int index { get; set; }
public BitmapImage Image { get; set; }
public string Name { get; set; }
public int Duration { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
}
private ObservableCollection<MyListItem> _yourCollection = new ObservableCollection<MyListItem>();
public ObservableCollection<MyListItem> YourCollection
{
get { return _yourCollection; }
set { _yourCollection = value; }
}
我按照以下方式填充您的收集项目
for (int i = 0; i < noofimage; i++)
{
YourCollection.Add(new MyListItem { index = i, Duration = JSONscript.playlist.Contents[i].Duration, Name = JSONscript.playlist.Contents[i].Name, Description = JSONscript.playlist.Contents[i].Description, Image = new BitmapImage(new Uri(Imagepath[i], UriKind.Absolute)), IsActive = false });
}
我尝试按如下方式设置进度的IsActive,但它不起作用
if (YourCollection[videoindex].IsActive)
YourCollection[videoindex].IsActive = false;
else
YourCollection[0].IsActive = true;
答案 0 :(得分:1)
Add INotifyPropertyChanged
到您的模型类MyListItem
当您从集合中添加或删除项目时,UI将获得一个事件,但是如果单个对象本身发生更改则不会...因此请使用上面的界面