示例#1
0
        public AssociatedDocListBoxItem(String labeltext, String imageUri, String _scatteruri, ArtworkModeWindow lb, string description)
        {
            _helpers = new Helpers();
            _description = description;
            scatteruri = _scatteruri;
            _lb = lb;
            opened = false;
            dp = new DockPanel();
            this.Content = dp;
            //if image
            if (_helpers.IsImageFile(_scatteruri))
            {
                image = new Image();
                _helpers = new Helpers();

                FileStream stream = new FileStream(imageUri, FileMode.Open);

                System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);
                System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage);
                stream.Close();

                wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left);

                wpfImage.SetCurrentValue(HeightProperty, 50.0);
                wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height);

                dp.Children.Add(wpfImage);

                label = new Label();
                label.Content = labeltext;
                label.FontSize = 18;
                label.SetCurrentValue(DockPanel.DockProperty, Dock.Right);
                dp.Children.Add(label);
                this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch);
                this.PreviewMouseDown += new MouseButtonEventHandler(onTouch);
                lb.getAssociatedDocToolBar().Items.Add(this);
            }

            //equivalent for videos
            else if (_helpers.IsVideoFile(_scatteruri))
            {
                if (_helpers.IsDirShowFile(_scatteruri)) //can easily create nice thumbnails of the video using DirectShow
                {
                    image = new Image();

                    imageUri = System.IO.Path.GetFullPath(imageUri);
                    int decrement = System.IO.Path.GetExtension(imageUri).Length;
                    imageUri = imageUri.Remove(imageUri.Length - decrement, decrement);
                    imageUri += ".bmp";
                    FileStream stream = new FileStream(imageUri, FileMode.Open);

                    System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);
                    System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage);
                    stream.Close();

                    wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left);
                    wpfImage.SetCurrentValue(HeightProperty, 50.0);
                    wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height);

                    dp.Children.Add(wpfImage);

                    label = new Label();
                    label.Content = labeltext;
                    label.FontSize = 18;
                    label.SetCurrentValue(DockPanel.DockProperty, Dock.Right);
                    dp.Children.Add(label);
                    this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch);
                    this.PreviewMouseDown += new MouseButtonEventHandler(onTouch);
                    lb.getAssociatedDocToolBar().Items.Add(this);
                }
                //Code for not actually creating thumbnails of videos, but instead creating paused, unplayable media elements to act as thumbnails
                else
                {
                    MediaElement thumVid = new MediaElement();
                    thumVid.Source = new Uri(scatteruri, UriKind.RelativeOrAbsolute);

                    thumVid.LoadedBehavior = MediaState.Manual;
                    thumVid.ScrubbingEnabled = true;
                    thumVid.Play();
                    thumVid.Pause();

                    thumVid.Position = new TimeSpan(0, 0, 0, 0);
                    thumVid.SetCurrentValue(DockPanel.DockProperty, Dock.Left);
                    thumVid.SetCurrentValue(HeightProperty, 50.0);
                    thumVid.SetCurrentValue(WidthProperty, 50 * thumVid.Width / thumVid.Height);

                    dp.Children.Add(thumVid);

                    label = new Label();
                    label.Content = labeltext;
                    label.FontSize = 18;
                    label.SetCurrentValue(DockPanel.DockProperty, Dock.Right);
                    dp.Children.Add(label);
                    this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch);
                    this.PreviewMouseDown += new MouseButtonEventHandler(onTouch);
                    lb.getAssociatedDocToolBar().Items.Add(this);
                }
            }
        }