0

我有这堂课,

public class ImageBox : Grid
    {
        Image imgclose; public String path;
        List<ImageBox> ImageBoxes;
        public ImageBox(string label,List<ImageBox> ImBox)
        {
            this.ImageBoxes = ImBox;
            imgclose = new Image();
            imgclose.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Close.ico"));
            imgclose.Width = 20; imgclose.Height = 20; imgclose.Cursor = Cursors.Hand; imgclose.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; imgclose.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            imgclose.Visibility = System.Windows.Visibility.Hidden;
            imgclose.MouseLeftButtonDown += new MouseButtonEventHandler(imgclose_MouseLeftButtonDown);
            this.MouseEnter += new MouseEventHandler(Blank_MouseEnter);
            this.MouseLeave += new MouseEventHandler(Blank_MouseLeave);            
            this.Height = 100; this.Width = 100;           
            try
            {
                System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();
                path = open.FileName.Replace(Directory.GetCurrentDirectory(), ""); 
                this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
                path = label;

            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            Grid.SetColumn(imgclose, 0); Grid.SetRow(imgclose, 1);            
            this.Children.Add(imgclose);

            ContextMenu contextMenu1 = new ContextMenu();
            MenuItem conitem1 = new MenuItem() { Header = "Send to back" }; conitem1.Click += new System.Windows.RoutedEventHandler(conitem1_Click);
            MenuItem conitem2 = new MenuItem() { Header = "Bring to Front" }; conitem2.Click += new System.Windows.RoutedEventHandler(conitem2_Click);
            contextMenu1.Items.Add(conitem1); contextMenu1.Items.Add(conitem2);
            this.ContextMenu = contextMenu1;
        }
        void conitem1_Click(object sender, EventArgs e)
        {
            Canvas.SetZIndex(this, (Canvas.GetZIndex(this) - 1));
        }
        void conitem2_Click(object sender, EventArgs e)
        {
            Canvas.SetZIndex(this, (Canvas.GetZIndex(this) + 1));
        }
        void Blank_MouseEnter(object sender, MouseEventArgs e)
        {
            imgclose.Visibility = System.Windows.Visibility.Visible;
        }

        void Blank_MouseLeave(object sender, MouseEventArgs e)
        {
            imgclose.Visibility = System.Windows.Visibility.Hidden;
        }
        void imgclose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (System.Windows.MessageBox.Show("Are you sure?", "Confirm", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.OK)
            {
                ImageBoxes.Remove(this);
                (this.Parent as System.Windows.Controls.Canvas).Children.Remove(this);
            }
            else
            {

            }
        }
    }

此类显示图像(从对话框中选择)。

如何修改它以使其播放视频文件?更准确地说,我应该如何修改该行

 this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
                path = label;

以便它播放视频文件。

4

1 回答 1

0

Background 属性中必须有某种 Brush。一个快速的谷歌搜索想出了这个:VideoBrush。我希望这就是你要找的。

于 2013-11-06T14:11:30.557 回答