当前位置:编程学习 > C#/ASP.NET >>

关于C#的Uri的问题,请高手帮忙

using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace Petzold.LoadXamlResource
{
    public class LoadXamlResource : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new LoadXamlResource());
        }
        public LoadXamlResource()
        {
            Title = "Load Xaml Resource";

            Uri uri = new Uri("pack://application:,,,/LoadXamlResource.xml");
            Application.GetResourceStream(uri);
            Stream stream = Application.GetResourceStream(uri).Stream;
            FrameworkElement el = XamlReader.Load(stream) as FrameworkElement;
            Content = el;

            Button btn = el.FindName("MyButton") as Button;

            if (btn != null)
                btn.Click += ButtonOnClick;
        }
        void ButtonOnClick(object sender,RoutedEventArgs args)
        {
            MessageBox.Show("The button labeled '" +
                            (args.Source as Button).Content +
                            "' has been clicked");
        }
    }
}

以上这段代码,运行到“Stream stream = Application.GetResourceStream(uri).Stream;”的时候报NullReferenceException,请问大神们什么原因,QQQ --------------------编程问答-------------------- 人工置顶 --------------------编程问答-------------------- 人工置顶 --------------------编程问答-------------------- 人工置顶 --------------------编程问答-------------------- 加断点,判断Application或Application.GetResourceStream(uri)哪个是空
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,