Permalink
Browse files

Fleshed out demo app/panorama to fetch from Last.fm

  • Loading branch information...
1 parent 8802abf commit 705355bccd1a7c81d5cf7a329b56843ede806e69 aeoth committed Oct 20, 2011
Showing with 35,383 additions and 238 deletions.
  1. BIN Lib/GrayscaleEffect.dll
  2. +26 −2 MahApps.Metro.Controls/Behaviours/TiltBehavior.cs
  3. +0 −1 MahApps.Metro.Controls/MahApps.Metro.Controls.csproj
  4. +1 −2 MahApps.Metro.Controls/MetroImage.cs
  5. +15 −37 MahApps.Metro.Controls/Panorama.cs
  6. +3 −2 MahApps.Metro.Controls/Tile.cs
  7. +0 −172 MahApps.Metro.Controls/TiltBehavior.cs
  8. +24 −0 MetroDemo/Artist.xaml.cs
  9. +7 −0 MetroDemo/Artists.xaml.cs
  10. +11 −0 MetroDemo/Image.xaml.cs
  11. +0 −1 MetroDemo/MainWindow.xaml.cs
  12. +11 −0 MetroDemo/MetroDemo.csproj
  13. +75 −7 MetroDemo/PanoramaDemo.xaml
  14. +32 −14 MetroDemo/PanoramaDemo.xaml.cs
  15. +3 −0 MetroDemo/Properties/DesignTimeResources.xaml
  16. +7 −0 MetroDemo/Wrapper.xaml.cs
  17. +4 −0 MetroDemo/packages.config
  18. BIN packages/Newtonsoft.Json.4.0.3/Newtonsoft.Json.4.0.3.nupkg
  19. BIN packages/Newtonsoft.Json.4.0.3/lib/net20/Newtonsoft.Json.dll
  20. BIN packages/Newtonsoft.Json.4.0.3/lib/net20/Newtonsoft.Json.pdb
  21. +7,859 −0 packages/Newtonsoft.Json.4.0.3/lib/net20/Newtonsoft.Json.xml
  22. BIN packages/Newtonsoft.Json.4.0.3/lib/net35/Newtonsoft.Json.dll
  23. BIN packages/Newtonsoft.Json.4.0.3/lib/net35/Newtonsoft.Json.pdb
  24. +6,982 −0 packages/Newtonsoft.Json.4.0.3/lib/net35/Newtonsoft.Json.xml
  25. BIN packages/Newtonsoft.Json.4.0.3/lib/net40/Newtonsoft.Json.dll
  26. BIN packages/Newtonsoft.Json.4.0.3/lib/net40/Newtonsoft.Json.pdb
  27. +7,141 −0 packages/Newtonsoft.Json.4.0.3/lib/net40/Newtonsoft.Json.xml
  28. BIN packages/Newtonsoft.Json.4.0.3/lib/sl3-wp/Newtonsoft.Json.dll
  29. BIN packages/Newtonsoft.Json.4.0.3/lib/sl3-wp/Newtonsoft.Json.pdb
  30. +6,574 −0 packages/Newtonsoft.Json.4.0.3/lib/sl3-wp/Newtonsoft.Json.xml
  31. BIN packages/Newtonsoft.Json.4.0.3/lib/sl4/Newtonsoft.Json.dll
  32. BIN packages/Newtonsoft.Json.4.0.3/lib/sl4/Newtonsoft.Json.pdb
  33. +6,604 −0 packages/Newtonsoft.Json.4.0.3/lib/sl4/Newtonsoft.Json.xml
  34. +4 −0 packages/repositories.config
Binary file not shown.
@@ -46,9 +46,22 @@ public Int32 TiltFactor
protected override void OnAttached()
{
attachedElement = AssociatedObject;
-
+ if (attachedElement is ListBox)
+ {
+ var l = (ListBox) attachedElement;
+ l.Items.CurrentChanging += (s, e) =>
+ {
+ Console.WriteLine("foo");
+ };
+ return;
+ }
if (attachedElement as Panel != null)
{
+ var y = (attachedElement as ItemsControl);
+ y.Items.CurrentChanging += (s, e) =>
+ {
+ Console.WriteLine("foo");
+ };
(attachedElement as Panel).Loaded += (sl, el) =>
{
List<UIElement> elements = new List<UIElement>();
@@ -71,7 +84,8 @@ protected override void OnAttached()
return;
}
- OriginalPanel = attachedElement.Parent as Panel;
+ OriginalPanel = attachedElement.Parent as Panel ?? GetParentPanel(attachedElement);
+
OriginalMargin = attachedElement.Margin;
OriginalSize = new Size(attachedElement.Width, attachedElement.Height);
double left = Canvas.GetLeft(attachedElement);
@@ -167,5 +181,15 @@ current.Y < (attachedElement).ActualHeight)
}
}
}
+
+ private static Panel GetParentPanel(DependencyObject element)
+ {
+ var parent = VisualTreeHelper.GetParent(element);
+ if (parent is Panel)
+ return (Panel)parent;
+ return parent == null ? null : GetParentPanel(parent);
+ }
}
+
+
}
@@ -79,7 +79,6 @@
<DependentUpon>RevealImage.xaml</DependentUpon>
</Compile>
<Compile Include="Tile.cs" />
- <Compile Include="TiltBehavior.cs" />
<Compile Include="ToggleSwitch.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@@ -11,8 +11,7 @@ public MetroImage()
DefaultStyleKey = typeof(MetroImage);
}
- public static readonly DependencyProperty SourceProperty =
- DependencyProperty.Register("Source", typeof(Visual), typeof(MetroImage), new PropertyMetadata(default(Visual)));
+ public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(Visual), typeof(MetroImage), new PropertyMetadata(default(Visual)));
public Visual Source
{
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -16,57 +17,55 @@ public class Panorama : ItemsControl
public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register("ItemHeight", typeof(double), typeof(Panorama), new PropertyMetadata(Double.NaN));
private double _currentWidth = -1;
- private Action<String> _goToState;
private double _increment;
private bool _mouseCaptured;
- public Panorama()
+ private double GetWidths()
{
+ return Items.Cast<PanoramaItem>().Sum(i => i.ActualWidth);
+ }
- DefaultStyleKeyProperty.OverrideMetadata(typeof(Panorama), new FrameworkPropertyMetadata(typeof(Panorama)));
-
+ public Panorama()
+ {
+ DefaultStyleKey = typeof(Panorama);
Loaded += (s, e) =>
{
foreach (var ob in Items)
{
var panoramaItem = ob as PanoramaItem;
- if (panoramaItem != null)
- {
- panoramaItem.RenderTransform = new TranslateTransform();
- SetOpacity(panoramaItem);
- }
+ if (panoramaItem == null)
+ continue;
+
+ panoramaItem.RenderTransform = new TranslateTransform();
}
};
- _goToState = (s) => VisualStateManager.GoToElementState(this, s, true);
var c = 0;
CompositionTarget.Rendering += (s, e) =>
{
if (_mouseCaptured && Mouse.LeftButton == MouseButtonState.Released)
{
_mouseCaptured = false;
_currentWidth = -1;
- var w = -1 * ((Double.IsNaN(ItemWidth)) ? ActualWidth : ItemWidth);
+ var w = -1 * GetWidths();
if (Traslation < (Items.Count - 1) * w)
{
c = Items.Count - 1;
}
else if (Traslation < 0)
{
- if (Math.Abs(Traslation) + c * w > 20)
+ if (Math.Abs(Traslation) + c * -ActualWidth > 20)
c += 1;
- else if (Math.Abs(Traslation) + c * w < -20)
+ else if (Math.Abs(Traslation) + c * -ActualWidth < -20)
c -= 1;
-
- c = c > Items.Count - 1 ? Items.Count - 1 : c;
}
else
{
c = 0;
}
- Animate(Traslation, Math.Min(0, c * w));
+ Animate(Traslation, Math.Min(0, c * -ActualWidth) + 100);
return;
}
@@ -129,7 +128,6 @@ public double Traslation
{
var currentpanorama = (ob as PanoramaItem);
((TranslateTransform)(currentpanorama.RenderTransform)).X = value;
- SetOpacity(currentpanorama);
}
}
}
@@ -145,19 +143,6 @@ protected override void PrepareContainerForItemOverride(DependencyObject element
panoramaItem.Height = ItemHeight;
}
-
- private void SetOpacity(PanoramaItem item)
- {
- double t = Math.Abs(((TranslateTransform)(item.RenderTransform)).X);
- double w = ((Double.IsNaN(ItemWidth)) ? ActualWidth : ItemWidth);
- double op = t / w + 1;
- double idx = Items.IndexOf(item);
- op = op - idx;
- op = op > 1 ? 1 : op;
- op = op < 0.5 ? 0 : op;
- item.HeaderOpacity = op;
- }
-
private bool MouseOver()
{
Point p = Mouse.GetPosition(this);
@@ -172,13 +157,6 @@ private TranslateTransform RenderTranslateTransform(object ob)
private void Animate(double begin, double end)
{
var da = new DoubleAnimationUsingKeyFrames();
- da.CurrentTimeInvalidated += (s, e) =>
- {
- foreach (PanoramaItem ob in Items)
- {
- SetOpacity(ob);
- }
- };
da.Completed += (s, e) =>
{
foreach (object ob in Items)
@@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
+using MahApps.Metro.Controls.Behaviours;
namespace MahApps.Metro.Controls
{
@@ -14,8 +15,8 @@ public Tile()
void TileLoaded(object sender, RoutedEventArgs e)
{
- var behaviours = Interaction.GetBehaviors(this);
- behaviours.Add(new TiltBehavior { TiltFactor = 5 });
+ //var behaviours = Interaction.GetBehaviors(this);
+ //behaviours.Add(new TiltBehavior { TiltFactor = 5 });
}
#region public string Title
@@ -1,172 +0,0 @@
-using System;
-using System.Linq;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Input;
-using System.Windows.Interactivity;
-using System.Windows.Media;
-
-namespace MahApps.Metro.Controls
-{
- public class TiltBehavior : Behavior<FrameworkElement>
- {
- public static readonly DependencyProperty KeepDraggingProperty =
- DependencyProperty.Register("KeepDragging", typeof(bool), typeof(TiltBehavior), new PropertyMetadata(true));
-
-
- public static readonly DependencyProperty TiltFactorProperty =
- DependencyProperty.Register("TiltFactor", typeof(Int32), typeof(TiltBehavior), new PropertyMetadata(20));
-
- private bool _isPressed;
-
-
- private Thickness _originalMargin;
- private Panel _originalPanel;
- private Size _originalSize;
- private FrameworkElement _attachedElement;
-
-
- private Point _current = new Point(-99, -99);
- private Int32 _times = -1;
-
- public bool KeepDragging
- {
- get { return (bool)GetValue(KeepDraggingProperty); }
- set { SetValue(KeepDraggingProperty, value); }
- }
-
- public Int32 TiltFactor
- {
- get { return (Int32)GetValue(TiltFactorProperty); }
- set { SetValue(TiltFactorProperty, value); }
- }
-
- public Planerator RotatorParent { get; set; }
-
- protected override void OnAttached()
- {
- _attachedElement = AssociatedObject;
-
- if (_attachedElement as Panel != null)
- {
- (_attachedElement as Panel).Loaded += (sl, el) =>
- {
- var elements = (_attachedElement as Panel).Children.Cast<UIElement>().ToList();
-
- elements.ForEach(
- element =>
- Interaction.GetBehaviors(element).Add(
- new TiltBehavior
- {
- KeepDragging = KeepDragging,
- TiltFactor = TiltFactor
- }));
- };
-
- return;
- }
-
- _originalPanel = _attachedElement.Parent as Panel;
- _originalMargin = _attachedElement.Margin;
- _originalSize = new Size(_attachedElement.Width, _attachedElement.Height);
- double left = Canvas.GetLeft(_attachedElement);
- double right = Canvas.GetRight(_attachedElement);
- double top = Canvas.GetTop(_attachedElement);
- double bottom = Canvas.GetBottom(_attachedElement);
- int z = Panel.GetZIndex(_attachedElement);
- VerticalAlignment va = _attachedElement.VerticalAlignment;
- HorizontalAlignment ha = _attachedElement.HorizontalAlignment;
-
- #region Setting Container Properties
-
- RotatorParent = new Planerator
- {
- Margin = _originalMargin,
- Width = _originalSize.Width,
- Height = _originalSize.Height,
- VerticalAlignment = va,
- HorizontalAlignment = ha
- };
- RotatorParent.SetValue(Canvas.LeftProperty, left);
- RotatorParent.SetValue(Canvas.RightProperty, right);
- RotatorParent.SetValue(Canvas.TopProperty, top);
- RotatorParent.SetValue(Canvas.BottomProperty, bottom);
- RotatorParent.SetValue(Panel.ZIndexProperty, z);
-
- #endregion
-
- #region Removing Child Properties
-
- _originalPanel.Children.Remove(_attachedElement);
- _attachedElement.Margin = new Thickness();
- _attachedElement.Width = double.NaN;
- _attachedElement.Height = double.NaN;
-
- #endregion
-
- _originalPanel.Children.Add(RotatorParent);
- RotatorParent.Child = _attachedElement;
-
- CompositionTarget.Rendering += CompositionTargetRendering;
- }
-
- private void CompositionTargetRendering(object sender, EventArgs e)
- {
- if (KeepDragging)
- {
- _current = Mouse.GetPosition(RotatorParent.Child);
- if (Mouse.LeftButton == MouseButtonState.Pressed)
- {
- if (_current.X > 0 && _current.X < (_attachedElement).ActualWidth && _current.Y > 0 &&
- _current.Y < (_attachedElement).ActualHeight)
- {
- RotatorParent.RotationY = -1 * TiltFactor + _current.X * 2 * TiltFactor / (_attachedElement).ActualWidth;
- RotatorParent.RotationX = -1 * TiltFactor + _current.Y * 2 * TiltFactor / (_attachedElement).ActualHeight;
- }
- }
- else
- {
- RotatorParent.RotationY = RotatorParent.RotationY - 5 < 0 ? 0 : RotatorParent.RotationY - 5;
- RotatorParent.RotationX = RotatorParent.RotationX - 5 < 0 ? 0 : RotatorParent.RotationX - 5;
- }
- }
- else
- {
- if (Mouse.LeftButton == MouseButtonState.Pressed)
- {
- if (!_isPressed)
- {
- _current = Mouse.GetPosition(RotatorParent.Child);
- if (_current.X > 0 && _current.X < (_attachedElement).ActualWidth && _current.Y > 0 &&
- _current.Y < (_attachedElement).ActualHeight)
- {
- RotatorParent.RotationY = -1 * TiltFactor +
- _current.X * 2 * TiltFactor / (_attachedElement).ActualWidth;
- RotatorParent.RotationX = -1 * TiltFactor +
- _current.Y * 2 * TiltFactor / (_attachedElement).ActualHeight;
- }
- _isPressed = true;
- }
-
-
- if (_isPressed && _times == 7)
- {
- RotatorParent.RotationY = RotatorParent.RotationY - 5 < 0 ? 0 : RotatorParent.RotationY - 5;
- RotatorParent.RotationX = RotatorParent.RotationX - 5 < 0 ? 0 : RotatorParent.RotationX - 5;
- }
- else if (_isPressed && _times < 7)
- {
- _times++;
- }
- }
- else
- {
- _isPressed = false;
- _times = -1;
- RotatorParent.RotationY = RotatorParent.RotationY - 5 < 0 ? 0 : RotatorParent.RotationY - 5;
- RotatorParent.RotationX = RotatorParent.RotationX - 5 < 0 ? 0 : RotatorParent.RotationX - 5;
- }
- }
- }
- }
-}
Oops, something went wrong. Retry.

0 comments on commit 705355b

Please sign in to comment.