2013-05-03 100 views
0

我在运行时在WPF中创建资源文件。在运行时在wpf中添加现有项目到解决方案

它正在资源文件夹中创建并显示,但即​​使在刷新文件夹后,它也不会在解决方案中显示。

当我手动(add exsiting item),然后它被添加。

如何在创建解决方案时将其添加到解决方案中?

我的代码是:

public void LaguageCulture(string languageid) 
{ 
    try 
    { 
     SqlParameter[] param = new SqlParameter[1]; 
     param[0] = new SqlParameter("@lagid", languageid); 
     //languageid =3 
     var dsResources = SqlHelper.ExecuteDataset(_objSqlConnection, "sproc_GetResourceNames", param); 
     string culturecode = string.Empty; 
     if (dsResources.Tables[1].Rows.Count > 0) 
     { 
      culturecode = dsResources.Tables[1].Rows[0][0].ToString(); 
     } 
     FileInfo file = new FileInfo(System.Windows.Forms.Application.StartupPath.Replace("\\bin\\Debug", "") + "\\Resources\\EnglishResource." + culturecode + ".resx"); // Culture code is en-US 
     if (!file.Exists) 
     { 
      var resx = new ResXResourceWriter(System.Windows.Forms.Application.StartupPath.Replace("\\bin\\Debug", "") + "\\Resources\\EnglishResource." + culturecode + ".resx"); 
      if (dsResources.Tables[0].Rows.Count > 0) 
      { 
       for (var i = 0; i < dsResources.Tables[0].Rows.Count; i++) 
       { 
        resx.AddResource(dsResources.Tables[0].Rows["ResourceName"].ToString(), dsResources.Tables[0].Rows["ResourceValue"].ToString()); 
       } 
      } 
      resx.Generate(); 
      //Application.Current.Resources.Add(culturecode + ".resx", resx); 
      resx.Close(); 
     } 
     System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culturecode); 
     System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culturecode); 
    } 
    catch (Exception) 
    { 
     throw; 
    } 
} 
+1

我不知道理解的问题,但我猜你将不得不操纵'csproj'或'sln'文件来达到自己的目标。 – 2013-05-03 09:42:57

回答

0

你必须在编程添加一些行的.csproj(这是一个XML文件)。

也许是这样的:

<EmbeddedResource Include="Resources\EnglishResource.en-US.resx"> 
    <Generator>PublicResXFileCodeGenerator</Generator> 
</EmbeddedResource> 
相关问题