Windows phone 8 如何在Windows Phone 8中筛选可观察的集合?
我尝试了这个方法,所以我尝试了这个方法,但它不适合我,因为windows phone 8环境找不到“ListCollectionView” 我的收藏如下Windows phone 8 如何在Windows Phone 8中筛选可观察的集合?,windows-phone-8,filter,listbox,collectionview,listcollectionview,Windows Phone 8,Filter,Listbox,Collectionview,Listcollectionview,我尝试了这个方法,所以我尝试了这个方法,但它不适合我,因为windows phone 8环境找不到“ListCollectionView” 我的收藏如下 //My observableCollection ObservableCollection<ClonedWrapper> dsForProgress = new ObservableCollection<ClonedWrapper >(); //My Function which shows at first tim
//My observableCollection
ObservableCollection<ClonedWrapper> dsForProgress = new ObservableCollection<ClonedWrapper >();
//My Function which shows at first time.
private async Task CloudImages()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
try
{
List<MainWrapper> serverdata = new List<MainWrappe>();
serverdata = await ImageUrlAsync();//This function is returning the Deserialize object of images
if (serverdata.Count != 0)
{
foreach (var imgInfo in serverdata)
{
string folderPath = "Fagbokforlaget/Books/" + BookInfo.Id.Trim();
ClonedWrapper item = new ClonedWrapper()
{
//Name, Cover, Info, Title, IsEnableButton, IsVisibleButton,
// IsVisible are the assigned keys to the xaml page
Id = imgInfo.Id,
Name = imgInfo.Name,
Cover = await GetCoverImage(imgInfo),
Info = imgInfo.Info,
Title = imgInfo.Title,
Url = imgInfo.Url,
IsEnableButton = "True",
IsVisible = "Collapsed",
Date = Convert.ToDateTime(imgInfo.Date)
};
if (isf.DirectoryExists(folderPath))
{
item.ButtonStatus = "Read";
item.IsVisibleBookDeleteButton = "Visible";
}
else
{
item.ButtonStatus = "Download";
item.IsVisibleBookDeleteButton = "Collapsed";
}
dsForProgress.Add(item);
}
}
else
{
MessageBox.Show("You have no any downloaded books!");
}
listCloudImages.ItemsSource = dsForProgress;
}
catch (Exception exe)//I am getting exception here on extreme first run in absense of internet.
{
MessageBox.Show(exe.Message);
}
}
//我的observableCollection
ObservableCollection dsForProgress=新的ObservableCollection();
//第一次显示的我的函数。
私有异步任务CloudImages()
{
IsolatedStorageFile isf=IsolatedStorageFile.GetUserStoreForApplication();
尝试
{
List serverdata=new List();
serverdata=Wait ImageUrlAsync();//此函数返回图像的反序列化对象
如果(serverdata.Count!=0)
{
foreach(serverdata中的var imgInfo)
{
字符串folderPath=“Fagbokforlaget/Books/”+BookInfo.Id.Trim();
ClonedWrapper项=新ClonedWrapper()
{
//姓名、封面、信息、标题、IsEnableButton、IsVisibleButton、,
//IsVisible是分配给xaml页面的键
Id=imgInfo.Id,
Name=imgInfo.Name,
封面=等待获取封面图片(imgInfo),
Info=imgInfo.Info,
Title=imgInfo.Title,
Url=imgInfo.Url,
IsEnableButton=“True”,
IsVisible=“折叠”,
日期=Convert.ToDateTime(imgInfo.Date)
};
如果(isf.DirectoryExists(folderPath))
{
item.ButtonStatus=“读取”;
item.IsVisibleBookDeleteButton=“可见”;
}
其他的
{
item.ButtonStatus=“下载”;
item.IsVisibleBookDeleteButton=“折叠”;
}
dsForProgress.Add(项目);
}
}
其他的
{
Show(“您没有任何下载的书籍!”);
}
listCloudImages.ItemsSource=dsForProgress;
}
catch(Exception exe)//在没有互联网的情况下,我在极端第一次运行时遇到异常。
{
MessageBox.Show(exe.Message);
}
}
//我的xaml页面如下。它是第一次加载的默认页面。你可以说这是应用程序的外观。用户下载图片。和按钮状态转换为读取按钮。所以现在我所做的我将在appliationbar中保留两个按钮,一秒钟下载一次。单击“下载”按钮,我只想显示下载的图像。
<ListBox Name="listCloudImages" Visibility="Visible" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Auto" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Thin" Margin="0,0,0,50">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<tools:WrapPanel Orientation="Horizontal">
</tools:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" Background="#151414" CornerRadius="3" Margin="3" Width="150" TextOptions.DisplayColorEmoji="True" BorderBrush="#1c1b1b">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgBookImage" Source="{Binding Cover}" Visibility="Visible" VerticalAlignment="Top" HorizontalAlignment="Center"
Width="80" Height="100" ImageOpened="imgBookImage_ImageOpened"/>
<StackPanel Orientation="Horizontal">
<TextBlock Visibility="{Binding IsVisible}" Text="{Binding ProgressPercentage}" FontFamily="Segoe UI" FontSize="18" FontWeight="ExtraBold" Foreground="White" Margin="5,0"></TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" FontFamily="Segoe UI" FontSize="13.5"
Foreground="White" TextTrimming="WordEllipsis"
VerticalAlignment="Top" HorizontalAlignment="Left"
TextWrapping="Wrap"
Width="300" Padding="2"/>
<TextBlock Text="{Binding Info}" FontSize="13.5" FontFamily="Segoe UI"
Foreground="White"
VerticalAlignment="Top" HorizontalAlignment="Left"
TextWrapping="Wrap"
Width="300" Padding="2"/>
<ProgressBar x:Name="downloadProgressBar" Foreground="Green" IsIndeterminate="True" VerticalAlignment="Center" Width="120" TextOptions.TextHintingMode="Animated" Visibility="{Binding IsVisible}" CharacterSpacing="2"/>
<Button Content="{Binding ButtonStatus}" x:Name="btnDownload" IsEnabled="{Binding IsEnableButton, Converter={StaticResource ButtonVisibilityIsEnableConverter}}"
Click="btnDownload_Click" Tag="{Binding}" Width="120" BorderThickness="1" FontSize="13.5" Margin="0,5"
FontFamily="Segoe UI" tools:SlideInEffect.LineIndex="2" HorizontalAlignment="Left" VerticalAlignment="Top"
Foreground="White">
</Button>
<Image x:Name="imgCancelImage" Source="/Assets/Tiles/CancelImage.png" Visibility="{Binding IsVisible}" VerticalAlignment="Center" Margin="97,-66,0,0"
Tap="imgCancelImage_Tap" HorizontalAlignment="Right" Width="25" Height="25" Tag="{Binding}"/>
<Button x:Name="btnDeleteImage" Click="btnDeleteImage_Click"
Tag="{Binding}" BorderThickness="1" Margin="97,-66,0,0"
Height="55" Width="55"
Visibility="{Binding ButtonStatus, Converter={StaticResource DeleteButtonVisibilityConverter}}">
<Button.Background>
<ImageBrush ImageSource="/Images/delete.png" Stretch="Fill"></ImageBrush>
</Button.Background>
</Button>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在您的图书模型中,您可以传递bool属性IsDownload,当您下载图书时,您可以将此属性设置为true。对于您的筛选器,只需使用linQ进行take all books download或no download,如下所示:
var noDownloadedBooks =
from b in yourObservableCollection
where b.IsDownload == false
select b;
var downloadedBooks =
from b in yourObservableCollection
where b.IsDownload == true
select b;
您需要做的是使用CollectionViewSource,它可以指向您的原始集合,并且可以处理过滤!
Scott Hanselman在这里有一篇很好的博客文章 根据您的代码,您可以做一些非常简单的事情,如果您只想显示下载的书籍,请尝试以下操作:
private void ApplicationBarButtonShowAllDownLoaded(object sender, EventArgs e)
{
var c = (Application.Current as App).dsForProgress.Where(x => x.ButtonStatus.Equals("Download"));
listCloudImages.ItemsSource = c;
}
确保
可观察到的收集进度数据
是公开的至少,向我们展示您的collection@SeeSharp我现在已经展示了我的收藏。请帮助。我无法创建//以下行已写入我的代码中。xmlns:d=”“//需要写入以下行,但它会继续显示//错误,这意味着路径中找不到my HomePage.xaml。而//我的路径是正确的。d:DataContext=“{d:DesignData MyWpPhone/HomePage.xaml}”仅凭此注释很难检查错误!但是你可以查看下面的运行示例,也许你可以根据自己的需要对其进行调整谢谢亲爱的,我想再说一件事,你们都是如何解决这些问题的。你的头脑很好。:)我希望上帝保佑我有这样的想法……:)无论如何,再次谢谢你。