2011-02-11 21 views
0

我開發了一個web應用程序,它包含一個部分,我使用xml文件填充組合框。現在我需要開發WPF應用程序,它使用相同的XML文件執行相同的操作。將片段轉換爲wpf格式組合框

我的問題是這樣的:我可以重新使用一段代碼片段嗎?我如何修改它?我明白我不能使用.DataTextField .DataSource和.DataBind因爲我不能使用的System.Web命名空間

public void PopulateDDLFromXMLFile() 
{ 
    DataSet ds = new DataSet(); 
    ds.ReadXml("C:\abc.xml"); 


    DataView dv = ds.Tables["builder"].DefaultView; 
    DataView dw = ds.Tables["manager"].DefaultView; 

    dv.Sort = "value"; 

    comboBox1.DataTextField = "value"; 
    comboBox2.DataTextField = "value"; 
    comboBox1.DataSource = dv; 
    comboBox1.DataBind(); 
    comboBox2.DataSource = dw; 
    comboBox2.DataBind(); 

} 
+0

System.Web進入到這裏? – 2011-02-11 07:34:46

+0

你試過了嗎?結果或錯誤是什麼?我沒有看到這個代碼在WPF上工作的任何問題。 – 2011-02-11 07:36:20

回答

1

不太清楚,但我認爲它會必須有一些事情在那個方向:

public void PopulateDDLFromXMLFile() 
    { 
     DataSet ds = new DataSet(); 
     ds.ReadXml("C:\abc.xml"); 


     DataView dv = ds.Tables["builder"].DefaultView; 
     DataView dw = ds.Tables["manager"].DefaultView; 

     dv.Sort = "value"; 

     comboBox1.ItemsSource = dv; //Sets the collection of items from which to populate 
     comboBox2.ItemsSource = dw; 

     comboBox1.DisplayMemberPath = "value"; //Sets the path within an item to use for display 
     comboBox2.DisplayMemberPath = "value"; 
    }