当我单击 中的项目时,以下 XAML 会产生运行时绑定错误ListBox:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<x:Array x:Key="strings" Type="{x:Type sys:String}">
<sys:String>one</sys:String>
<sys:String>two</sys:String>
<sys:String>three</sys:String>
<sys:String>four</sys:String>
</x:Array>
</Window.Resources>
<Grid>
<ListBox
DataContext="{StaticResource strings}"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
SelectedValuePath="{Binding /Length}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Background" Value="Yellow"/>
<Setter Property="Margin" Value="0,0,4,0"/>
<Setter Property="Padding" Value="0"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<!-- Row 0 -->
<Label Grid.Column="0" Grid.Row="0">String:</Label>
<TextBlock
Grid.Column="1"
Grid.Row="0"
Text="{Binding}"/>
<!-- Row 1 -->
<Label Grid.Column="0" Grid.Row="1">Length:</Label>
<TextBlock
Grid.Column="1" …Run Code Online (Sandbox Code Playgroud) MVCContrib Grid中优雅的Action语法为我们提供了Empty()方法.但是,默认行为MvcContrib.UI.Grid.GridRenderer<T>.RenderHeader()是在网格为空时隐藏表列标题.有没有一种方法可以在不存在不需要重大重构的数据时显示标题?
现在我听说默认隐藏标题并硬编码,但这对我来说并不酷.
顺便说一句,这是在引擎盖下发生的事情MvcContrib.UI.Grid.GridRenderer<T>:
protected virtual bool RenderHeader()
{
//No items - do not render a header.
if(! ShouldRenderHeader()) return false;
RenderHeadStart();
foreach(var column in VisibleColumns())
{
//Allow for custom header overrides.
if(column.CustomHeaderRenderer != null)
{
column.CustomHeaderRenderer(new RenderingContext(Writer, Context, _engines));
}
else
{
RenderHeaderCellStart(column);
RenderHeaderText(column);
RenderHeaderCellEnd();
}
}
RenderHeadEnd();
return true;
}
protected virtual bool ShouldRenderHeader()
{
return !IsDataSourceEmpty();
}
protected bool IsDataSourceEmpty()
{
return DataSource == null …Run Code Online (Sandbox Code Playgroud) 这个问题让我Task想到了另一个更普遍(也可能是根本)的问题,为什么对象不可重用?
微软在没有解释的情
任务只能启动并仅运行一次.任何第二次安排任务的尝试都将导致异常.
这背后的推理是如此明显,以至于它不值得解释吗?重复设置和启动Task延迟是否没有性能损失?
我还没有注意到,詹姆斯·牛顿写的国王或者谈到什么JToken 是.我做了一个错误的假设,它以某种方式持有一个参考JObject.情况并非如此,因为这些LINQPad语句演示了:
var json = @"
{
""item"": {
""foo"": ""4"",
""bar"": ""42""
}
}
";
var jO = JObject.Parse(json);
var jToken = jO["item"]["foo"];
jToken = "5";
jO.ToString().Dump("jO");
jToken.Dump("jToken");
Run Code Online (Sandbox Code Playgroud)
输出:
jO
{
"item": {
"foo": "4",
"bar": "42"
}
}
jToken
5
Run Code Online (Sandbox Code Playgroud)
不应该jO["item"]["foo"] == 5?
鉴于一些CreditScoreInput:
type CreditScoreInput = { id: string; score: string; years: int }
let input = [
{ id = "CUSTOMER001"; score = "Medium"; years = 1 }
{ id = "CUSTOMER001"; score = "Medium"; years = 1 }
{ id = "CUSTOMER002"; score = "Medium"; years = 10 }
{ id = "CUSTOMER003"; score = "Bad"; years = 0 }
{ id = "CUSTOMER003"; score = "Bad"; years = 0 }
{ id = "CUSTOMER003"; score = "Bad"; …Run Code Online (Sandbox Code Playgroud) 我想确保我没有错过可读但简洁的 F# 语法:我使用fun下面的语法是否过于冗长?
let toCamelCase word indexes =
let mapping i c =
match (indexes |> List.contains i) with
| true -> Char.ToUpper(c)
| _ when Char.IsUpper(c) -> Char.ToLower(c)
| _ -> c
word |> String.mapi mapping
[
("fsharP", [0; 1])
("nAtiveinterop", [0; 6])
("taskbuildereXtensions", [0; 4; 11])
("microsoftword", [0; 9])
]
|> List.map (fun (word, indexes) -> (word, indexes) ||> toCamelCase)
Run Code Online (Sandbox Code Playgroud)
另外,请告诉我上面代码中的其他地方是否可以改进
请考虑以下函数体:
var isValidated = true;
$(selector1).each(function(){
//do validation with local f()...
isValidated = f() && isValidated;
});
$(selector2).each(function(){
//do validation with local f()...
isValidated = f() && isValidated;
});
$(selector3).each(function(){
//do validation with local f()...
isValidated = f() && isValidated;
});
return isValidated;
Run Code Online (Sandbox Code Playgroud)
我对进展的描述isValidated是布尔级联 - 但是必须有一个官方的,计算机科学的术语.它是什么?为了澄清,这里的想法是让每个$()块运行---但是当这些块中的任何一个块具有验证失败时,该失败的结果必须返回false所有块(true && true && false == false).因此,像许多程序员一样,我使用某种模式,但我们常常不知道它叫什么.那么这种模式有什么用呢?
我仍然在.NET 4.0中,我想知道这种模式在各种异步单元测试情况下是否能够很好地保持:
/// <summary>
/// Noaa weather test: should read remote XML.
/// </summary>
[TestMethod]
public void ShouldReadRemoteXml()
{
var uri = new Uri("http://www.weather.gov/xml/current_obs/KLAX.xml");
var wait = HttpVerbAsyncUtility.GetAsync(uri)
.ContinueWith(
t =>
{
Assert.IsFalse(t.IsFaulted, "An unexpected XML read error has occurred.");
Assert.IsTrue(t.IsCompleted, "The expected XML read did not take place.");
if(t.IsCompleted && !t.IsFaulted)
FrameworkFileUtility.Write(t.Result, @"NoaaWeather.xml");
})
.Wait(TimeSpan.FromSeconds(7));
Assert.IsTrue(wait, "The expected XML read did not take place within seven seconds.");
}
Run Code Online (Sandbox Code Playgroud)
这种Task.ContinueWith()...Task.Wait()模式会在现实世界中持续存在吗?我对正式考虑单元测试(特别是异步单元测试)比较新,所以请不要停留在基础知识上:)
IDictionary切换到from后,我不仅看到了性能的提高Map(这是在 10 多年前的一个问题中探讨的),而且当我从这个切换到 from 时,我的速度甚至更快了type:
type MyCollection =\n\n static member Collection = [\n (1, "one")\n (2, "two")\n ...\n ] |> dict\n\n static member Get id = MyCollection.Collection[id]\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\xa6 到这样的类型:
\ntype MyCollection() =\n\n static let collection = [\n (1, "one")\n (2, "two")\n ...\n ] |> dict\n\n static member Get id = collection[id]\nRun Code Online (Sandbox Code Playgroud)\n为什么使用static letover时性能会提高static member?
有没有一个例子向我展示Observable.Count<TSource> Method实际如何运作?我想出的例子似乎返回一个包含在observable中的计数而不是预期的计数.
例如,我希望1从这里返回:
System.Diagnostics.Debug.WriteLine((Observable.Return<string>("Hello world!")).Count());
Run Code Online (Sandbox Code Playgroud)
将来会1被退回(因为,毕竟它是一个异步序列)?或者我错过了一些基本的东西?在撰写本文时,我实际上假设只要结果被推出,.Count()它将返回结果T并随着时间的推移而增长.真?是.
c# ×3
f# ×3
.net ×2
asp.net-core ×1
asp.net-mvc ×1
boolean ×1
collections ×1
javascript ×1
json.net ×1
lambda ×1
linqpad ×1
mstest ×1
mvccontrib ×1
wpf ×1
xaml ×1