2013-03-26 83 views
1

所有,我是WPF的新手。我想閱讀.resx文件和所有與不同文化有關的文件;例如默認的'en-GB'.resx文件,稱爲'SomeFile.resx'和'SomeFile.de-DE.resx'德文模擬器。當然,我可以擁有與各種文化相關的大量不同的.resx文件。在運行時將行和列添加到WPF數據網格

所以,我想讀的所有不同的文化資源轉化爲一個DataGrid,讓我有類似

Resource Index | Resource Key | English (Default) | German 
1    | SomeKey1  | Run Script  | Skript Ausführen 
2    | SomeKey2  | OK    | OK 

等。我的問題是將此數據添加到名爲dataGridDataGrid的最佳方法。所以,我目前得到可用的非默認.resx文件爲Dictionary<string, string>

Dictionary<string, string> cultureDict = new Dictionary<string, string>(); 

然後我打算使用ResXResourceReader閱讀像這樣的.resx文件通過不同的.resx文件循環(對於衆多的文化)

Dictionary<string, string> resourceMap = new Dictionary<string, string>(); 

public static void Func(string fileName) 
{ 
    ResXResourceReader rsxr = new ResXResourceReader(fileName);   
    foreach (DictionaryEntry d in rsxr) 
    { 
     resourceMap.Add(d.Key.ToString(),d.Value.ToString());   
    }   
    rsxr.Close(); 
} 

public string GetResource(string resourceId) 
{ 
    return resourceMap[resourceId]; 
} 

我曾計劃建立一個List<Dictionary<string, string>>保存從讀者的不同文化通過List的信息,然後循環,並添加行。

我的問題是什麼是把從這些讀者返回的數據爲DataGrid牢記文化的數量是可變的和潛在的大最好的和最有效的方法是什麼?

謝謝你的時間。

注:我可以添加列

DataGridTextColumn itemColumn = new DataGridTextColumn(); 
itemColumn.Header = "Item Number"; 
itemColumn.Binding = new Binding("Item Number"); 
dataGrid.Columns.Add(itemColumn); 

但它是添加的行,這種特殊情況下的最佳方式。

回答

1
public static void Display_Grid(DataGrid d, List<string> S1) 
{ 
    ds = new DataSet(); 
    DataTable dt = new DataTable(); 
    ds.Tables.Add(dt); 

    DataColumn cl = new DataColumn("Item Number", typeof(string)); 
    cl.MaxLength = 200; 
    dt.Columns.Add(cl); 

    int i = 0; 
    foreach (string s in S1) 
    { 
     DataRow rw = dt.NewRow(); 
     rw["Item Number"] = S1[i]; 
     i++; 
    } 
    d.ItemsSource = ds.Tables[0].AsDataView(); 
} 
相關問題