|
using System;
using System.Windows;
using System.Xml.Linq;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MediaPlayer
{
public partial class HorizontalGallery : UserControl
{
public enum GalleryCount : int
{
Big = 6,
Small = 3
}
int vidPointer = 0;
XDocument xDoc;
int btnClickedFlag = 1;
private GalleryCount galleryMode;
public GalleryCount GalleryMode
{
get { return galleryMode; }
set
{
galleryMode = value;
if (galleryMode == GalleryCount.Big)
{
GalleryHeight = 50;
}
else
{
GalleryHeight = 100;
}
}
}
double galleryHeight = 50;
double GalleryHeight
{
get { return galleryHeight; }
set
{
galleryHeight = value;
ucHGallery.Height = value;
}
}
public HorizontalGallery()
{
InitializeComponent();
}
private void Button_LClick(object sender, RoutedEventArgs e)
{
if (vidPointer == 0)
return;
rect.Visibility = Visibility.Visible;
hideMenu.Begin();
btnClickedFlag = -1;
}
private void Button_RClick(object sender, RoutedEventArgs e)
{
if (vidPointer + (int)GalleryMode >= GetTotalCount())
return;
rect.Visibility = Visibility.Visible;
hideMenu.Begin();
btnClickedFlag = 1;
}
private void DoubleAnimation_Completed(object sender, EventArgs e)
{
ShowNext();
showMenu.Begin();
}
private int GetTotalCount()
{
var xVids = from v in xDoc.Descendants("Video")
where v.Attribute("img").Value.Length > 0 && v.Attribute("vid").Value.Length > 0
select v;
return xVids.Count();
}
private void ShowNext()
{
vidPointer = vidPointer + (btnClickedFlag * (int)GalleryMode);
if (vidPointer < 0)
vidPointer = 0;
var xVids = from v in xDoc.Descendants("Video")
where System.Convert.ToInt32(v.Attribute("id").Value) >= vidPointer
&& v.Attribute("img").Value.Length > 0 && v.Attribute("vid").Value.Length > 0
&& System.Convert.ToInt32(v.Attribute("id").Value) < (vidPointer + (int)GalleryMode)
select new
{
img = v.Attribute("img").Value,
vid = v.Attribute("vid").Value,
id = v.Attribute("id").Value
};
imgGallery.Children.Clear();
foreach (var v in xVids)
{
Image img = new Image();
img.Source = new BitmapImage(new Uri(v.img, UriKind.Relative));
img.Height = galleryHeight;
img.Margin = new Thickness(1, 0, 1, 0);
imgGallery.Children.Add(img);
}
}
public void HGalleryInit()
{
xDoc = XDocument.Load("Data.xml");
var xVids = from v in xDoc.Descendants("Video")
where System.Convert.ToInt32(v.Attribute("id").Value) >= vidPointer
&& v.Attribute("img").Value.Length > 0 && v.Attribute("vid").Value.Length > 0
&& System.Convert.ToInt32(v.Attribute("id").Value) < (vidPointer + (int)GalleryMode)
select new
{
img = v.Attribute("img").Value,
vid = v.Attribute("vid").Value,
id = v.Attribute("id").Value
};
imgGallery.Children.Clear();
foreach (var v in xVids)
{
Image img = new Image();
img.Source = new BitmapImage(new Uri(v.img, UriKind.Relative));
img.Height = galleryHeight;
img.Margin = new Thickness(1, 0, 1, 0);
imgGallery.Children.Add(img);
}
}
private void DoubleAnimation_Completed_1(object sender, EventArgs e)
{
rect.Visibility = Visibility.Collapsed;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
B.E. in Information Technology
MCTS(.NET 2.0 )