How to create UI elements lazily in WPF?

We are creating a WPF application which makes heavy use of highly decorated input elements. A simple example of decorated element is a TextBox which looks like a read-only TextBlock when it doesn't have focus, and turns into a TextBox after receiving focus. Also, additional visual feedback is provided when the changed value is being saved to database. The problem is that showing a view tha

如何在WPF中懒洋洋地创建UI元素?

我们正在创建一个大量使用高度装饰的输入元素的WPF应用程序。 装饰元素的一个简单示例是TextBox,它在没有焦点时看起来像只读TextBlock,并在接收焦点后变为TextBox。 另外,当更改的值被保存到数据库时会提供额外的视觉反馈。 问题是,显示一个包含很多这些元素的视图(比方说100)非常慢,并且使应用程序非常无响应。 我们已经实现了这个装饰器作为UserControl,它包含了所有必需的元素(例如TextBlock显示未聚焦的文本和

Best way to get a user to input a correctly

I am creating a dialog using MVVM which prompts the user to type in an http:// URL to a KML file. The "OK" button needs to be enabled when the URL is in the correct format, and it needs to be disabled when the URL is in an incorrect format. Right now the button is bound to an ICommand, and the logic for CanExecute() looks like this: return !string.IsNullOrEmpty(CustomUrl); The comm

让用户正确输入的最佳方式

我使用MVVM创建一个对话框,它提示用户输入一个http://到KML文件的URL。 当URL格式正确时,需要启用“确定”按钮,并且URL格式不正确时需要禁用该按钮。 现在,该按钮绑定到一个ICommand,并且CanExecute()的逻辑如下所示: return !string.IsNullOrEmpty(CustomUrl); 每个击键都会引发该命令的CanExecuteChanged事件,并且到目前为止它运行良好。 现在我想做一些实际验证。 我知道要做到这一点的唯一方法如下: try {

How to use Log4Net utility for logging into database using c#

This question already has an answer here: Storing Log4Net Messages in SQL Server 2 answers You can have a look here, I think this is exactly what you need. Note that if you want to use log4net from a client application and write to a database, you might want to consider to put a service in between. In that case you can easily write your own log4net adapter that calls your LogService (fire

如何使用Log4Net实用程序使用c#登录到数据库

这个问题在这里已经有了答案: 在SQL Server 2中存储Log4Net消息的答案 你可以看看这里,我想这正是你需要的。 请注意,如果您想从客户端应用程序使用log4net并写入数据库,则可能需要考虑在两者之间放置服务。 在这种情况下,您可以轻松编写自己的log4net适配器,该适配器调用登录到数据库(可能使用MSMQ)的LogService(fire and forget)。

Expressing type relationships and avoiding long type parameter lists in C#

I have this situation (drastically simplified): interface IPoint<TPoint> where TPoint:IPoint<TPoint> { //example method TPoint Translate(TPoint offset); } interface IGrid<TPoint, TDualPoint> where TPoint:IPoint<T where TDualPoint:Ipoint { TDualPoint GetDualPoint(TPoint point, /* Parameter specifying direction */); } Here is typical implementation: clas

在C#中表达类型关系并避免使用长类型参数列表

我有这种情况(急剧简化): interface IPoint<TPoint> where TPoint:IPoint<TPoint> { //example method TPoint Translate(TPoint offset); } interface IGrid<TPoint, TDualPoint> where TPoint:IPoint<T where TDualPoint:Ipoint { TDualPoint GetDualPoint(TPoint point, /* Parameter specifying direction */); } 这是典型的实现: class HexPoint : IPoint<HexPoint>

How to write NDEF record across multiple blocks with MIFARE 1k classic?

I writing an application in C# that writes a NDEF record to a MIFARE 1k tag. Im using the ACR122 contactless card reader to send APDU commands. The record that I want to write is URI type, and it needs to be long, so thats where my problem begins. So far Im able to write to whichever block I want, but I can only read what is written in the first sector (blocks 4,5 and 6). blocks 8 and 9 (se

如何使用MIFARE 1k classic在多个块中编写NDEF记录?

我用C#编写一个应用程序,将NDEF记录写入MIFARE 1k标签。 Im使用ACR122非接触式读卡器发送APDU命令。 我想写的记录是URI类型,它需要很长时间,所以这就是我的问题开始的地方。 到目前为止,我能够写入任何想要的块,但我只能读取第一个扇区中写入的内容(块4,5和6)。 块8和9(第二个扇区)有内容但不能被读取。 因为我不能写入扇区块,所以我从块6跳转到8.所以,我不确定是否必须设置一个字节,指示消息在另一个块上

Force throwing of exception when a source property is unmapped

In AutoMapper 2.2.1, is there any way I can configure my mappings so that when a property is not explicitly ignored, an exception is thrown? For example, I have the following classes and configuration: public class Source { public int X { get; set; } public int Y { get; set; } public int Z { get; set; } } public class Destination { public int X { get; set; } public int Y {

当源属性未映射时强制抛出异常

在AutoMapper 2.2.1中,有没有什么办法可以配置我的映射,以便当某个属性没有被显式忽略时抛出异常? 例如,我有以下类和配置: public class Source { public int X { get; set; } public int Y { get; set; } public int Z { get; set; } } public class Destination { public int X { get; set; } public int Y { get; set; } } // Config Mapper.CreateMap<Source, Destination>(); 我通过

list of structs from managed C++ to C#

First off, I would like to reference to this question: Sharing variables between C# and C++. It seems to be what I'm looking for, but when trying to implement this, I get some errors. First off this is my code: C++ MyCppWrapper.h namespace CppWrapping { #pragma pack(1) public struct MyPoint { public: float X; float Y; float Z; unsigned c

从托管C ++到C#的结构列表

首先,我想引用这个问题:在C#和C ++之间共享变量。 这似乎是我正在寻找的,但是当试图实现这一点,我得到一些错误。 首先,这是我的代码: C ++ MyCppWrapper.h namespace CppWrapping { #pragma pack(1) public struct MyPoint { public: float X; float Y; float Z; unsigned char R; unsigned char G; unsigned char B; unsigned char A;

How to track checks in checkedListBox C#?

I try to display the number of checked items in the checkedListBox: checkedListBox1.CheckedIndices.Count But how can i update my count, if i want to display it on label? I tried to write all in the ItemCheck event: private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { label1.Text= checkedListBox1.CheckedIndices.Count; } But the count increase

如何跟踪checkedListBox C#中的检查?

我尝试显示checkedListBox中checked项目的数量: checkedListBox1.CheckedIndices.Count但是我如何更新我的计数,如果我想在标签上显示它呢? 我试图在ItemCheck事件中写入所有内容: private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { label1.Text= checkedListBox1.CheckedIndices.Count; } 但计数增加,即使我取消选中项目:(我会很感激任何帮助! 只需添加一个

Request.ServerVariables throws NullReferenceException

I have an MVC3 application, which is suddenly giving me some strange behavior. First some background (although I'll try to make this as brief as possible). In my controller action, I have this code: public ActionResult Grid(ApplicationViewModel search = null) { return this.ListView( this.Find<Entity>(), this.CreateViewModel, mixins: new Dictionary<stri

Request.ServerVariables抛出NullReferenceException

我有一个MVC3应用程序,它突然给我一些奇怪的行为。 首先是一些背景(尽管我会尽量使其尽可能简短)。 在我的控制器操作中,我有这样的代码: public ActionResult Grid(ApplicationViewModel search = null) { return this.ListView( this.Find<Entity>(), this.CreateViewModel, mixins: new Dictionary<string, Func<EntityViewModel, object>>() { {

Calculating difference between different columns in different rows

I have a table that records what happens to a vehicle during a visit. For each visit, there is are multiple rows to denote what has been done. The table looks like this VisitID | ActionID | StartTime | EndTime 0 | 0 | 1/1/2013 | 1/2/2013 1 | 0 | 1/2/2013 | 1/4/2013 1 | 1 | 1/4/2013 | 1/7/2013 2 | 0 | 1/4/2013 | 1/5/2013 2 | 1

计算不同行中不同列之间的差异

我有一张桌子,记录访问期间车辆发生的情况。 对于每次访问,都有多行来表示已完成的操作。 桌子看起来像这样 VisitID | ActionID | StartTime | EndTime 0 | 0 | 1/1/2013 | 1/2/2013 1 | 0 | 1/2/2013 | 1/4/2013 1 | 1 | 1/4/2013 | 1/7/2013 2 | 0 | 1/4/2013 | 1/5/2013 2 | 1 | 1/5/2013 | 1/6/2013 2 | 2 | 1/6/2013 | 1/7/2013