我找到了这样的代码来动态创建一个Grid和一些列:
Grid grd = new Grid();
ColumnDefinition c = new ColumnDefinition();
c.Width = new GridLength(50, GridUnitType.Pixel);
. . .
grd.ColumnDefinitions.Add(c);
Run Code Online (Sandbox Code Playgroud)
但是我想创建具有相对宽度的列,这些列对应于xaml中使用的"*":
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
Run Code Online (Sandbox Code Playgroud)
如何动态使用这些相对宽度值/比率?
我有一个项目的源,但是缺少.resx文件,这会阻止编译.有没有办法为它重新生成resx文件?这是我在XP机器上使用Visual Studio 2010 Professional创建的C#项目,我试图在Windows 8计算机上使用Visual Studio 2012 Ultimate打开它.
它(Resources.resx)实际上在那里(在属性下),所以我猜"无法找到"意味着:"我不喜欢你给我的那个."
当我对F6进行另一次尝试时,我收到警告,"自定义工具'ResXFileCodeGenerator'与文件'Properties\Resources.resx'相关联,但是在项目中找不到自定义工具的输出.尝试通过右键单击解决方案资源管理器中的文件并选择"运行自定义工具"来重新运行自定义工具."
另外:"自定义工具'SettingsSingleFileGenerator'与文件'Properties\Settings.settings'相关联,但在项目中找不到自定义工具的输出.您可以尝试通过右键单击重新运行自定义工具解压缩资源管理器中的文件并选择运行自定义工具."
我为Resources.resx和Settings.settings运行了"运行自定义工具",仍然得到相同的错误和两个警告.
根据这篇文章,一个Controller应该有一个构造函数来获取要传入的接口,一个la:
public class DuckbillsController : ApiController
{
IDuckbillRepository _platypiRepository;
public DuckbillsController(IDuckbillRepository platypiRepository)
{
if (platypiRepository == null)
{
throw new ArgumentNullException("platypiRepository is null");
}
_platypiRepository = platypiRepository;
}
}
Run Code Online (Sandbox Code Playgroud)
但这个构造函数是如何调用的呢?通过客户端调用此类中包含的Web API方法,但是如何通过接口类型传递?或者这不一定发生(构造函数没有被任何人/从任何地方明确调用)?
规范示例在接口声明之前显示"private readonly",但是编译它不是必需的.是否有编译,我的意思是引人注目,有理由,让我先加上"私人只读"?
c# controller ioc-container constructor-injection asp.net-web-api
我有以下HTML:
<form>
<table border="1">
<tr>
<td>Traveler's name:</td>
<td>
<input type="text" id="travelername" placeholder="Last Name, First Name, Middle Initial"/>
</td>
</tr>
<tr>
<td>Traveler's E-mail:</td>
<td>
<input type="email" id="traveleremail"/>
</td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
我希望占位符val始终完全可见,但它不是:
我尝试添加这个CSS:
input[placeholder] {
font-size: 0.6em;
}
Run Code Online (Sandbox Code Playgroud)
...但是,虽然这会令人钦佩地缩小字体大小,但文本会被截断:
我尝试像这样添加到CSS:
input[placeholder] {
font-size: 0.6em;
width: 500;
}
Run Code Online (Sandbox Code Playgroud)
...但是在输入文本中扩展/扩展占位符的文本区域没有任何作用(输入文本足够宽以容纳缩小的文本,但它本身仍然被压缩成一个太小的区域).
如何实现这一目标?
此代码适用于使单元格的背景为蓝色:
DataGridViewRow dgvr = dataGridViewLifeSchedule.Rows[rowToPopulate];
dgvr.Cells[colName].Style.BackColor = Color.Blue;
dgvr.Cells[colName].Style.ForeColor = Color.Yellow;
Run Code Online (Sandbox Code Playgroud)
...但ForeColor的效果并不是我所期望/希望的:字体颜色仍然是黑色,而不是黄色.
如何将字体颜色设置为黄色?
我从Adam Freeman的书"Metro Revealed:使用XAML和C#构建Windows 8应用程序"中获取/调整了以下代码,以便在知道坐标时获取地址:
public static async Task<string> GetAddressForCoordinates(double latitude, double longitude)
{
HttpClient httpClient = new HttpClient {BaseAddress = new Uri("http://nominatim.openstreetmap.org")};
HttpResponseMessage httpResult = await httpClient.GetAsync(
String.Format("reverse?format=json&lat={0}&lon={1}", latitude, longitude));
JsonObject jsonObject = JsonObject.Parse(await httpResult.Content.ReadAsStringAsync());
return jsonObject.GetNamedObject("address").GetNamedString("road");
Run Code Online (Sandbox Code Playgroud)
}
如何获得相反的结果(如果已知地址,则为坐标)?
我正在为此增加一笔赏金; 我已经得到的(如上所示)是反向地理编码(获取坐标的地址); 我需要的是地理编码(获取地址的坐标).
基于我上面的反向地理编码代码,我猜它可能是这样的:
public static async Task<string> GetCoordinatesForAddress(string address)
{
HttpClient httpClient = new HttpClient {BaseAddress = new Uri("http://nominatim.openstreetmap.org")};
HttpResponseMessage httpResult = await httpClient.GetAsync(
String.Format("format=json&address={0}", address));
JsonObject jsonObject = JsonObject.Parse(await httpResult.Content.ReadAsStringAsync());
return jsonObject.GetNamedObject("address").GetNamedString("lat"); // <-- what about "lon"?
} …Run Code Online (Sandbox Code Playgroud) 我在这里的"返回"行有一个断点:
[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
return NRBQClient.GetTestMessage(id1, id2);
}
Run Code Online (Sandbox Code Playgroud)
虽然它没有崩溃应用程序,当我达到这一点,我得到,
" Exception:Thrown:"不支持文化."(System.Globalization.CultureNotFoundException)抛出了System.Globalization.CultureNotFoundException:"不支持文化. "
试图支持哪种文化,为什么不支持这种文化,以及我应该做些什么来支持这种文化?
回答sphanley:
除了代表"BarbeQue的新骑士"之外,它还是一个"骨架"(现在)实体看起来像这样:
public class NRBQEntity
{
public NRBQEntity()
{
}
public String Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
对AnotherUser的回答:
这不是我的代码,所以我只是在试图理解它; 它作为一个起点提供给我复制/重构一个现有的独立项目,并将其纳入"解决方案".已经说过,回答你的问题,这里是解决方案中"GetTestMessage()"的所有实例:
[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
return NRBQClient.GetTestMessage(id1, id2);
}
[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
return NRBQService.GetNRBQEntity(id1, id2);
}
public interface INRBQClient
{
NRBQEntity GetTestMessage(String id1, String id2);
}
public NRBQEntity …Run Code Online (Sandbox Code Playgroud) 我想在Chart.JS水平条形图中将字体更改为snazzier.我尝试了以下,但没有一个有效:
var optionsBar = {
. . .
//fontFamily: "'Candara', 'Calibri', 'Courier', 'serif'"
//bodyFontFamily: "'Candara', 'Calibri', 'Courier', 'serif'"
//bodyFontFamily: "'Candara'"
label: {
font: {
family: "Georgia"
}
}
};
Run Code Online (Sandbox Code Playgroud)
我也读到这会起作用:
Chart.defaults.global.defaultFont = "Georgia"
Run Code Online (Sandbox Code Playgroud)
...但是这段代码会去哪里,它究竟应该如何?我试过这个:
priceBarChart.defaults.global.defaultFont = "Georgia";
Run Code Online (Sandbox Code Playgroud)
......但也没有好的效果.
对于完整的图片/上下文,以下是构成此图表的所有代码:
HTML
<div class="chart">
<canvas id="top10ItemsChart" class="pie"></canvas>
<div id="pie_legend"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
JQUERY
var ctxBarChart =
$("#priceComplianceBarChart").get(0).getContext("2d");
var barChartData = {
labels: ["Bix Produce", "Capitol City", "Charlies Portland",
"Costa Fruit and Produce", "Get Fresh Sales",
"Loffredo East", "Loffredo West", "Paragon", "Piazza Produce"],
datasets: [ …Run Code Online (Sandbox Code Playgroud) 根据这里的答案:我应该卸载哪些(如果有的话)最近的Windows更新来重新启动Silverlight或纠正其他问题?,我卸载/重新安装Silverlight并重新启动.但是,现在,我收到了一个编译错误,即:
"未找到导入的项目"C:\ Program Files(x86)\ MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.CSharp.targets".确认声明中的路径是否正确,以及该文件存在于磁盘上."
它指向*.csproj文件中的这一行:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)
我完全不明白这是做什么的; 如果这是远方可以理解的东西,我需要做些什么才能解决这个难题?
当我尝试安装Silverlight 4工具时(因为有人表示是/解决方案,例如在Silverlight 4:解析Microsoft.Silverlight.CSharp.targets时未找到?),我得到"安装要求:
必须先安装与Silverlight Tools 4的语言版本匹配的Visual Studio 2010或Visual Web Developer Express 2010或Visual Phone Developer Express 2010,然后才能继续安装Silverlight Tools.Silverlight Tools提供其他语言版本http://go.microsoft.com/fwlink/?LinkId=177432."
我确实安装了VS 2010(SP1).我甚至安装了VS Express(2012)用于Web!
基于另一个提示,我还安装了Silverlight 4 SDK,但是在尝试现在只打开项目时,我得到了"你需要在打开Silverlight项目'Bla'之前安装最新的Silverlight Developer运行时." 它让我安装了Silverlight 5(再次).
我这样做了,但我重新启动了,并且......仍然得到同样的错误消息...
根据我在这里得到的线索:http://connect.microsoft.com/VisualStudio/feedback/details/573750/the-imported-project-path-microsoft-webapplication-targets-was-not-found
我在csproj文件中替换了这一行:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)
......这一个:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)
......而且我比以前更进一步,但我不知道最后一次改变是否是必要的改动,或者如果上面列举的所有步骤都是必要的.除了影子,很可能没有人知道.
实际上,简单地添加该行(无需替换另一行),项目编译,但似乎失去了对Razor或其他东西的了解,因为它失败了这个YSOD:
Server Error in '/TLDReporter' Application.
Compilation Error
Description: An …Run Code Online (Sandbox Code Playgroud) c# ×6
css ×2
html ×2
.net ×1
bigdecimal ×1
chart.js2 ×1
controller ×1
csproj ×1
culture ×1
cultureinfo ×1
datagridview ×1
decimal ×1
dynamic ×1
fonts ×1
geocoding ×1
geolocation ×1
grid ×1
importerror ×1
java ×1
javascript ×1
jquery ×1
placeholder ×1
resx ×1
silverlight ×1
versioning ×1
winforms ×1
wpf ×1