Metro学习笔记(缩略图)
作者:互联网
Show.XAML
<Viewbox x:Name="viewBox" HorizontalAlignment="Left" Width="1366" Margin="0,0,0,-52" Grid.RowSpan="2" SizeChanged="viewBox_SizeChanged">
<GridView x:Name="gvShow" BorderThickness="10" BorderBrush="Black" HorizontalAlignment="Left" Grid.Row="1" Width="1366" Margin="0,5,0,0" Height="708" SelectionMode="None">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Tapped="Grid_Tapped_1" >
<StackPanel>
<Image x:Name="imgSmall" Width="400" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageSmall}" Stretch="UniformToFill"/>
</StackPanel>
<ScrollViewer x:Name="scrollViewer" BorderThickness="0" HorizontalAlignment="Center" ZoomMode="Enabled" MaxZoomFactor="20" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<Image x:Name="imgBig" Visibility="Collapsed" HorizontalAlignment="Left" Grid.Row="1" Source="{Binding ImageBig}" Stretch="UniformToFill"/>
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Viewbox>
Show.XAML.CS
async private void Open()
{
ObservableCollection<ImageItem> imageItemListBig = new ObservableCollection<ImageItem>();
ObservableCollection<ImageItem> imageItemListSmall = new ObservableCollection<ImageItem>();
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".gif");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".bmp");
var fileList = await openPicker.PickMultipleFilesAsync();
if (fileList.Count > 0)
{
foreach (var item in fileList)
{
//缩略图
using (StorageItemThumbnail thumbnail = await item.GetThumbnailAsync(ThumbnailMode.PicturesView, IMAGESIZE, ThumbnailOptions.ResizeThumbnail))
{
if (null != thumbnail)
{
ImageItem imageItemSmall = new ImageItem();
imageItemSmall.ImageSmall.SetSource(thumbnail);
imageItemListSmall.Add(imageItemSmall);
}
}
}
}
gvShow.ItemsSource = imageItemListSmall;
}
ImageIteam.cs
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
//缩略图
private BitmapImage _ImageSmall = new BitmapImage();
public BitmapImage ImageSmall
{
get
{
return _ImageSmall;
}
set
{
if (_ImageSmall != value)
{
_ImageSmall = value; this.OnPropertyChanged("ImageSmall");
}
}
}
//缩略图
public void SetImageSmall(String path)
{
ImageSmall = new BitmapImage(new Uri(path));
}
转载于:https://www.cnblogs.com/louyuhao/archive/2012/07/11/2586164.html
标签:ObservableCollection,Metro,ImageSmall,缩略图,笔记,Add,openPicker,new,FileTypeFilter 来源: https://blog.csdn.net/weixin_34060299/article/details/94562131