WPF后台加载文件的相对路径和绝对路径记载

      private void BindingInfo()
        {
            XmlDataProvider dp = new XmlDataProvider();
           // dp.Source = new Uri(@"C:\Users\zhoujm\Desktop\WpfApplication1\WpfApplication1\Resources\StudentData.xml");//绝对路径
            
            string path = "pack://application:,,,/Resources/StudentData.xml";//相对路径
            dp.Source = new Uri(@path);

            dp.XPath = @"StudentList/Student";
            this.listView1.DataContext = dp;
            this.listView1.SetBinding(ListView.ItemsSourceProperty, new Binding());

        }




     private void BindingDataByXml()
        {
           // XDocument xd = XDocument.Load(@"d:\我的文档\visual studio 2010\Projects\WpfApplication2\WpfApplication1\testDate.xml");
            XDocument xd = XDocument.Load("../../Resources/Manager.xml");
            this.listView1.ItemsSource = from element in xd.Descendants("Student")
                                         where element.Attribute("Name").Value.StartsWith("T")
                                         select new Student()
                                             {
                                                 Name = element.Attribute("Name").Value,
                                                 Id = Convert.ToInt32(element.Attribute("Id").Value),
                                                 Age = Convert.ToInt32(element.Attribute("Age").Value)
                                             };
        }

仅此记载,以便于日后查询

你可能感兴趣的:(WPF,WPF路径问题)