C#类播放视频文件

C#类播放视频文件,c#,class,video,C#,Class,Video,我有这门课 public class ImageBox : Grid { Image imgclose; public String path; List<ImageBox> ImageBoxes; public ImageBox(string label,List<ImageBox> ImBox) { this.ImageBoxes = ImBox;

我有这门课

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;