none
搞了两天的Image了!在线等啊!!! RRS feed

  • 问题

  • 希望按下button后 出现打开文件窗口
    选中一张图片后出现一张图片
    结果我代码能取到图片路径 就是不能显示图片!

    求助啊!搞这个东西我都要哭了!
    windo1.xaml文件
    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xml:lang="en-US"
        xmlnsBig Smile="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        x:Class="MySoftWare.Window1"
        x:Name="Window"
        Title="MySoftware"
        WindowState="Maximized" Canvas.Top="Auto">
        <Canvas>
            <Button Name="Open" Click="Open_Click">Open</Button>
            <Image Name="image" Canvas.Left="100" Canvas.Top="100"></Image>

        </Canvas>


    </Window>

    windows1.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;


    namespace MySoftWare
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
            }

            private void Open_Click(object sender, RoutedEventArgs e)
            {
                Microsoft.Win32.OpenFileDialog dialogOpenFile = new Microsoft.Win32.OpenFileDialog();
                dialogOpenFile.ShowDialog();
                if (dialogOpenFile.FileName != null)
                {
                    
                    Image pic = new Image();
                    Uri uri = new Uri(dialogOpenFile.FileName, UriKind.Absolute);
                    ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
                    pic.SetValue(Image.SourceProperty, img);

     
                }



            }
          
        }
    }

    求可以跑并显示图片的代码!
    2009年1月16日 3:16

答案

全部回复