2013-03-26 113 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(); 
} 
相关问题