<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<Style TargetType="Image">
<Setter Property="Margin" Value="-12,-36,0,0"/>
</Style>
</Grid.Resources>
<phone:Panorama x:Name="photoFlow1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="530">
</phone:Panorama>
</Grid>
private void AddPanoramaItem(LongMoreViewModel ItemNumber)
{
for (int i = 0; i < ItemNumber.Apps.Count; i++)
{
PanoramaItem Navitation = new PanoramaItem();
Image nimage = new Image();
nimage.RenderTransform = new CompositeTransform();
nimage.ManipulationDelta += Navitation_ManipulationDelta;
nimage.DoubleTap += Navitation_DoubleTap;
AppRecommend mde = ItemNumber.Apps[i] as AppRecommend;
nimage.Source= new BitmapImage(new Uri(mde.Name, UriKind.Absolute));
nimage.Stretch = System.Windows.Media.Stretch.Fill;
Navitation.Content = nimage;
photoFlow1.Items.Add(Navitation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
private void Navitation_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
Image grid = sender as Image;
if (grid == null)
return;
bool oldIsPinch = isPinching;
isPinching = e.PinchManipulation != null;
if (oldIsPinch == false && isPinching == false)
{
this.OnDragDelta(sender, e);
}
else if (oldIsPinch == false && isPinching == true)
{
this.OnPinchStarted(sender, e);
}
else if (oldIsPinch == true && isPinching == true)
{
this.OnPinchDelta(sender, e);
}
else if (oldIsPinch == true && isPinching == false)
{
this.OnPinchCompleted(sender, e);
}
}
private void OnDragDelta(object sender, ManipulationDeltaEventArgs e)
{
FrameworkElement framework = sender as FrameworkElement;
CompositeTransform compositeTransform = framework.RenderTransform as CompositeTransform;
if (compositeTransform.ScaleX == 1.0 && compositeTransform.ScaleY == 1.0)
return;
Point point = TransChanged(compositeTransform).Transform(e.DeltaManipulation.Translation);
compositeTransform.TranslateX += point.X;
compositeTransform.TranslateY += point.Y;
}
private GeneralTransform TransChanged(CompositeTransform trans)
{
CompositeTransform compositeTransform = new CompositeTransform();
compositeTransform.Rotation = trans.Rotation;
compositeTransform.ScaleX = trans.ScaleX;
compositeTransform.ScaleY = trans.ScaleY;
compositeTransform.CenterX = trans.CenterX;
compositeTransform.CenterY = trans.CenterY;
compositeTransform.TranslateX = 0.0;
compositeTransform.TranslateY = 0.0;
return (GeneralTransform)compositeTransform;
}
private void OnPinchStarted(object sender, ManipulationDeltaEventArgs e)
{
this.isPinching = true;
foreach (PanoramaItem item in photoFlow1.Items)
{
PanoramaItem pItem = photoFlow1.SelectedItem as PanoramaItem;
if (!item.Equals(pItem))
item.Visibility = Visibility.Collapsed;
}
}
private void OnPinchDelta(object sender, ManipulationDeltaEventArgs e)
{
FrameworkElement framework = sender as FrameworkElement;
CompositeTransform compositeTransform = framework.RenderTransform as CompositeTransform;
double scaleX = compositeTransform.ScaleX;
double deltaScale1 = e.PinchManipulation.DeltaScale;
double scaleY = compositeTransform.ScaleY;
double deltaScale2 = e.PinchManipulation.DeltaScale;
double num1 = compositeTransform.ScaleX * deltaScale1;
double num2 = compositeTransform.ScaleY * deltaScale2;
if (num2 > (double)this.maxScale || num1 > (double)this.maxScale)
{
compositeTransform.ScaleX = (double)this.maxScale;
compositeTransform.ScaleY = (double)this.maxScale;
}
else
{
compositeTransform.ScaleX = num1;
compositeTransform.ScaleY = num2;
}
}
private void OnPinchCompleted(object sender, ManipulationDeltaEventArgs e)
{
this.isPinching = false;
}
private void Navitation_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
FrameworkElement framework = sender as FrameworkElement;
CompositeTransform compositeTransform = framework.RenderTransform as CompositeTransform;
compositeTransform.ScaleX = compositeTransform.ScaleY = 1;
compositeTransform.CenterX = framework.Width / 2;
compositeTransform.CenterY = framework.Height / 2;
foreach (PanoramaItem item in photoFlow1.Items)
{
PanoramaItem pItem = photoFlow1.SelectedItem as PanoramaItem;
if (!item.Equals(pItem))
item.Visibility = Visibility.Visible;
}
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
<!--<phone:Panorama x:Name="photoFlow1" ItemsSource="{Binding Apps}" Margin="-12,0,-48,0">
<phone:Panorama.HeaderTemplate>
<DataTemplate>
<ContentControl Content="" FontSize="1"/>
</DataTemplate>
</phone:Panorama.HeaderTemplate>
<phone:Panorama.ItemTemplate>
<DataTemplate>
<Image Stretch="None" x:Name="Navitation" local:CCImage.Source="{Binding Name}"
ManipulationDelta="Navitation_ManipulationDelta" DoubleTap="Navitation_DoubleTap">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
</Image>
</DataTemplate>
</phone:Panorama.ItemTemplate>
</phone:Panorama>-->
public class LongMoreViewModel : BaseViewModel
{
public LongMoreViewModel()
{
Apps = new ObservableCollection<object>();
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/9418d78e-41d3-4010-b752-08a22f56a1bd?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/be2dac62-de4a-44bb-87bf-1f2b41d56df1?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/e0117eea-1cff-4c4b-835f-d00ebf4abe26?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/cb572d91-f0c1-4bdc-92b6-0b510801cf33?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/a6fa5c5d-f7a1-4c21-a5f8-0040383263ee?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/ac5a04d3-9a4a-4d40-9e7b-fa2db58b4e05?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/dcedb633-a6f7-4113-9211-598e30e38cca?imageType=ws_screenshot_large&rotation=0" });
Apps.Add(new AppRecommend() { Name = "http://cdn.marketplaceimages.windowsphone.com/v8/images/aa048089-c5de-426f-b313-462a2996c0b9?imageType=ws_screenshot_large&rotation=0" });
}
public IList<object> Apps { get; set; }
private BitmapImage imageSource;
/// <summary>
/// 获取或设置当前分享天气的图片.
/// </summary>
public BitmapImage ImageSource
{
get
{
return imageSource;
}
set
{
if (value != imageSource)
{
imageSource = value;
NotifyPropertyChanged("ImageSource");
}
}
}
}
public class AppRecommend
{
public string Name { get; set; }
public override bool Equals(object obj)
{
if ((obj != null) && (obj.GetType() == typeof(PanoramaItem)))
{
var thePanoItem = (PanoramaItem)obj;
return base.Equals(thePanoItem.Header);
}
else
{
return base.Equals(obj);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}