日期:2014-05-17  浏览次数:20468 次

请问WPF中上传文件或者打开文件怎么实现,类似上传图片的那个选择图片的功能
如题,怎么实现,望各位大侠指点

wpf刚接触,不知道有没有类似以前的那个 FileUPdate的控件,或者怎么可以实现这个效果

------解决方案--------------------
Microsoft.Win32.OpenFileDialog类打开文件.
上传的逻辑自己写
------解决方案--------------------
C# code

 private void FindPic_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "PNG File(*.png)|*.png"; ;
            dialog.Multiselect = false;

            if (dialog.ShowDialog() == true)
            {
                FileStream fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                this._imageBinary = br.ReadBytes((int)fs.Length);
                this._imgLocalPath = dialog.FileName;
                br.Close();
                fs.Close();
                this.IMG.Source = ByteArrayToBitmapImage(this._imageBinary);
            }
        }

BitmapImage ByteArrayToBitmapImage(byte[] byteArray)
        {
            BitmapImage bmp = null;

            try
            {
                bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.StreamSource = new MemoryStream(byteArray);
                bmp.EndInit();
            }
            catch
            {
                bmp = null;
            }

            return bmp;
        }