Tag: c# 4.0

我们如何为Window创建Singleton实例?

我已经搜索过在WPF中为窗口创建一个Singleton对象。 public static Test DefInstance { get { if (formDefInstance == null) // formDefInstance.IsDisposed { initializingDefInstance = true; formDefInstance = new cas18(); initializingDefInstance = false; } return formDefInstance; } set { formDefInstance = value; } } 但是forDefInstance.IsDisposed不起作用并抛出错误。 关于这个的任何想法?

以编程方式关闭USB端口的电源

我有一个项目,我正在努力,我想使用它们: http : //www.woot.com/blog/post/usb-powered-woot-off-lights-2 然而,看起来他们只有开/关开关。 它们不是您可以通过编程方式进行交互的东西。 所以我在想,如果我能找到一种方法来削减USB端口的电源,这将允许我用我的应用程序打开和关闭灯。 但是我找不到任何方法来切断USB端口的电源。 这可能吗?

如何在TemplateField中更改ItemTemplate的Command Text和ImageButton

我有一个有ImageButton的列。 我的数据库字段有bit数据类型。 我想当我的记录在该列中显示真值时显示True.jpg并且我的命令变为MakeFalse ,当它具有false值时显示False.jpg并且我的命令变为MakeTrue 。 我怎么能这样做?有可能用一个TemplateField吗? 谢谢

创建后面的datatemplate代码

我正在尝试为show数据创建一个ListBox视图,我希望它包含一个带有2列数据模板的ListBox“产品ID和产品条形码” 我想用纯C#代码创建它,或者如果可能的话通过xaml加载它? 如果我可以创建一个模板,我可以使用c#作为各种资源。 到目前为止我所做的是:在XAML中: 在代码背后: string typedString = txtCAuto.Text.ToUpper(); List autoList = new List(); autoList.Clear(); prodDetails ps = SelProd4Sale(); foreach (string item in ps.ProdBrcdList) { if (!string.IsNullOrEmpty(txtCAuto.Text)) { if (item.StartsWith(typedString)) { //autoList.Add(item); FrameworkElementFactory colProdID = new FrameworkElementFactory(typeof(TextBlock)); Binding prodID = new Binding(ps.ProdIDList.ToString()); colProdID.SetBinding(TextBlock.TextProperty, prodID); FrameworkElementFactory colProdBarcode = new FrameworkElementFactory(typeof(TextBlock)); Binding prodBarcode = new Binding(); prodBarcode.Path […]

反序列化对象将所有值设置为空

我正在尝试将JSON反序列化为自定义对象,但我的所有属性都设置为null并且不确定发生了什么。 有人看错了吗? JSON示例 { “Keys”: [ { “RegistrationKey”: “asdfasdfa”, “ValidationStatus”: “Valid”, “ValidationDescription”: null, “Properties”: [ { “Key”: “Guid”, “Value”: “i0asd23165323sdfs68661358” } ] } ] } 这是我的代码,其中strResponseValid是上面的JSON。 Keys myDeserializedObjValid = (Keys)JsonConvert.DeserializeObject(strResponseValid, typeof(Keys)); validationStatusValid = myDeserializedObjValid.ValidationStatus; 这是我的课程 public class Keys { public string RegistrationKey { get; set; } public string ValidationStatus { get; set; } public string […]

c#中的可选参数

我在以下代码中使用可选参数。 但是显示错误“不允许使用默认参数说明符”任何人都帮助我先生。 public void getno(int pvalu, string pname = “”) { }

如何准备Word 2007文档,以便C#可以从语义上提取数据?

我有一个朋友在Microsoft Word 2007中写了一本400页的书 。 在整本书中,他有200个故事,每个故事由许多段落组成。 当他完成这本书的编写后,他希望将嵌入在他的Word文档中的每个故事的文本复制到数据库表中,例如: Title, varchar(200) Description, text Content, text 我们不希望将每个故事复制并粘贴到数据库中,但希望程序自动将标记的数据从Word文件中提取到数据库中的相应字段中。 他必须在Microsoft Word中将每组段落表示为“故事内容”,将每个标题表示为“故事标题”等。先决条件是此标记在文档中不可见。 我知道Word 2007文件基本上是压缩的XML文件所以我认为这是可能的,我认为样式表是我们需要的,但我如何准确地准备Word文档,以便在添加故事时正确标记它们? 我假设C#4.0的新COM Interopfunction是我需要分析Word文件并仅从嵌入式故事中检索标题,描述和内容,但我如何在技术上做到这一点? 有人有例子吗? 有没有人有经验做这样的项目(阅读Microsoft Word作为semnatic数据文件),他们可以分享?

从任务并行库更新ProgressBar UI对象

基本上我想在FormMain(WindowsForm)上更新ProgressBar UI对象。 我使用的是.NET 4.0 以下是Form1.Designer.cs中的代码 namespace ProgressBarApp { public partial class Form1 : Form { private System.Windows.Forms.ProgressBar curProgressBar; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { CustomProcess theProcess = new CustomProcess(); theProcess.Process(); } } } 这是CustomProcess.cs的定义 namespace ProgressBarApp { class CustomProcess { public void Process() { for (int i = 0; […]

如何使用代码隐藏的c#隐藏html列表项

我想隐藏使用C#的“li”标签的html列表项。 但我不能这样做。 在早些时候我只是使用c#隐藏DIV标签。 但我无法隐藏“li”标签。 请帮我这样做。如果可以,请发送您的详细说明…… 这是我的部分代码: this.hide.style.Add(“display”, “none”); // Error in hide 这是我的HTML代码: list Approval 请帮我解决这个问题….

如何根据DataAnnotation中的另一个属性validation属性

考虑我有这两个属性: public class Test { [Required(ErrorMessage = “Please Enetr Age”)] public System.Int32 Age { get; set; } [Required(ErrorMessage = “Choose an option”)] public System.Boolean IsOld { get; set; } } 当用户为Age输入例如15并为IsOld选择“ Yes ”时,我返回一个正确的Age或IsOld的exception。 我已经使用了CustomValidation ,但因为我的validation必须是静态的,所以我无法访问其他属性。 我如何通过DataAnnotation执行此操作?