我有一个非常简单的可滚动日历UI:

但在滚动期间,日历会不时闪烁.我看过WPF Performance Suite,发现有大量的Dirty Rects(大约400个):

日历的标记是ItemsControl,它绑定Days(仅限可见天数).看起来像WPF一天一天地重绘(所以这就是为什么这么简单的用户界面有这么多脏的原因).我想可能有一种方法可以告诉WPF不要重绘许多小矩形但是一次重绘整个ItemsControl(类似于Double Buffering在WinForms的所有好日子里所做的).
PS WritableBitmap解决了这个问题,但我希望有一个更好的方法
更新.如果我切换"显示脏区更新覆盖"选项,则以下是Calendar的外观:

所以WPF正确地找到了脏区域.问题是为什么它决定使用这么多脏的重新绘制它.我的猜测是因为天数(白色的一个或两个像素)之间的空间在滚动期间是相同的.
更新2.
这是日历的标记:
<ItemsControl Panel.ZIndex="1" Grid.Column="1"
ItemsSource="{Binding Days}"
VerticalAlignment="Center"
HorizontalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="1,0,1,0" Padding="0,0,3,0"
CornerRadius="1" Width="28" Height="28"
VerticalAlignment="Top">
<Border.Background>
<MultiBinding Converter="{StaticResource DayOfWeekToColorConverter}">
<Binding Path="IsWeekend"/>
</MultiBinding>
</Border.Background>
<StackPanel>
<TextBlock Style="{StaticResource TextStyle}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Label Style="{StaticResource LabelStyle}"
Content="{Binding Date.Day}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud) 我需要格式化double类型,使其至少有两位小数,但不限制最大小数位数:
5 -> "5.00"
5.5 -> "5.50"
5.55 -> "5.55"
5.555 -> "5.555"
5.5555 -> "5.5555"
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它?
有没有办法让DataGridView适合colums/rows的宽度和高度?我找到了需要手动计算的解决方案:http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c9603 DataGridView真的不支持这个功能吗?
在使用jQuery发送到服务器之前,我一直在使用toISOString序列化momentJS日期.它对我来说很好,除了它将日期转换为UTC但我需要保留当地时区.momentJS有这个方法吗?
我有一个控制台应用程序,我希望它等到某个事件被提出.但它执行代码并退出:
static void Main(string[] args)
{
var someObjectInstance = new SomeObject();
someObjectInstance.SomeEvent += SomeEventHandler;
}
static void SomeEventHandler()
{
//Some logic
}
Run Code Online (Sandbox Code Playgroud)
我想让我的应用程序像Windows应用程序一样
Application.Run(new Form1());
Run Code Online (Sandbox Code Playgroud)
被调用并运行消息循环.
但我既不需要消息循环也不需要任何形式.所以它看起来像开销.是否有更轻量级的方式来实现我的目标?
与IDbTransaction相比,使用TransactionScope有什么优点/缺点?我会建议一些 - 请更正/填写清单.
TransactionScope的优点:
TransactionScope的缺点:
我的应用程序正在调试模式下执行,然后发生死锁.有没有办法在死锁或至少最后一个被调用的方法之前看到堆栈跟踪?
我有两种扩展方法:
public static IPropertyAssertions<T> ShouldHave<T>(this T subject)
{
return new PropertyAssertions<T>(subject);
}
public static IPropertyAssertions<T> ShouldHave<T>(this IEnumerable<T> subject)
{
return new CollectionPropertyAssertions<T>(subject);
}
Run Code Online (Sandbox Code Playgroud)
现在我写一些使用它的代码:
List<Customer> collection2 = new List<Customer>();
collection2.ShouldHave(); //first overload is chosen
IEnumerable<Customer> collection3 = new List<Customer>();
collection3.ShouldHave(); //second overload is chosen
Run Code Online (Sandbox Code Playgroud)
仅当我明确指定IEnumerable类型时才选择第二个重载.有没有办法在两种情况下都选择第二次过载?
通常我通过@ Html.RenderModel渲染我的表单,但这次我有一个复杂的渲染逻辑,我手动渲染它.我决定为一个属性创建一个编辑器模板.这是代码(从默认对象编辑器模板实现粘贴的副本):
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% var modelMetadata = ViewData.ModelMetadata; %>
<% if (modelMetadata.HideSurroundingHtml) { %>
<%= Html.Editor(modelMetadata.PropertyName) %>
<% } else { %>
<% if (!String.IsNullOrEmpty(Html.Label(modelMetadata.PropertyName).ToHtmlString())) { %>
<div class="editor-label"><%= Html.Label(modelMetadata.PropertyName) %></div>
<% } %>
<div class="editor-field">
<%= Html.Editor(modelMetadata.PropertyName) %>
<%= Html.ValidationMessage(modelMetadata.PropertyName) %>
</div>
<% } %>
Run Code Online (Sandbox Code Playgroud)
以下是我如何使用它:
@Html.EditorFor(x => x.SomeProperty, "Property") //"Property" is template above
Run Code Online (Sandbox Code Playgroud)
但它不起作用:无论DisplayName如何都会呈现标签,并且根本不呈现编辑器(在Watches Html.Editor中(modelMetadata.PropertyName显示空字符串).我做错了什么?
.net ×9
c# ×5
asp.net-mvc ×1
database ×1
debugging ×1
momentjs ×1
overloading ×1
transactions ×1
windows ×1
winforms ×1
wpf ×1