IEditableObject和IRevertibleChangeTracking(来自System.ComponentModel命名空间)有什么区别?看起来好像第一个支持显式事务而第二个支持更隐式 - 但最终结果是相同的.我应该如何在代码中实现它?目前我在BeginEdit中什么都不做,并分别在EndEdit和CancelEdit中调用RejectChanges和AcceptChanges.我的问题是,这也将接受在BeginEdit之前所做的更改.
这真的是微软想要的,还是我试图实现两个互斥的接口?
我上课了.有一次,我使用System.ComponentModel将类的属性设置为[Required] ....
好的,然后我意识到这不是必需的.我已经删除了所需的属性,但是当我尝试将表单提交给ActionResult时,表单不会发布,并且仍在尝试强制要填充TextBoxFor(theModelProperty).
我删除了"obj"文件夹,"bin"文件夹,还"清除"了解决方案.仍然没有决议.
我不想做一个愚蠢的解决方法,我想做正确的事情.知道为什么会这样吗?
asp.net-mvc componentmodel required data-annotations asp.net-mvc-3
为了在类中禁用组件设计器,只需向其添加[System.ComponentModel.DesignerCategory("")]属性即可,但它不适用于任何代中从此类派生的任何类.例如:
[System.ComponentModel.DesignerCategory("")]
public class A:ServiceBase { } //Designer is disabled here
public class B:A {} //Designer is enabled here
[System.ComponentModel.DesignerCategory("")]
public class B:A {} //Designer is enabled here too
[System.ComponentModel.DesignerCategory("Code")]
public class B:A {} //Designer is enabled even here
当然,这发生在任何其他世代和排列中.例如
//Whatever attribute here
public class C:B {} //Designer is enabled here
有没有人试图摆脱它?为什么组件模型尝试添加设计器支持,即使它在第一代中明确禁用?
谢谢
首先,我不得不说我要谈谈System.ComponentModel.Component.
您知道,我知道,.NET Component Model提供能力(通过站点服务)来定义单独的Components,因此它们可以以松散耦合的方式相互通信,并且每个都Component可以轻松替换.
但我要说的是,我能以其他方式做到这一点:我的意思是,如果我在正确的设计SW Object Oriented Programming的方式,我可以用的手段Abstract classes,Interfaces等实现上述所有的功能/互操作性.
那么为什么和何时我要依靠组件模型?
我刚刚创建了一个示例MVC3应用程序来学习验证.它正在使用DataAnnotations.我创建了一个名为CustomStartLetterMatch 的自定义ValidationAttribute.它正在实现"System.Web.Mvc.IClientValidatable".我有相应的客户端代码用不引人注目的jQuery编写.这是按预期工作的.
关于自定义验证器:它比较第一个名称输入和姓氏输入.如果它们的第一个字符不相同则抛出错误.
正如我所说,该应用程序工作正常.但是当我看着rule.ValidationType = "greaterdate";我感到困惑时.我想将其更改为"anotherDefaultType"之类的其他内容.当我更改它时,它失败并出现jQuery错误.
码:
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
namespace MyValidationTEST
{
    public class Person
    {
    [Required(ErrorMessage = "First name required")]
    public string FirstName { get; set; }
    [CustomStartLetterMatch("FirstName")]
    [StringLength(5,ErrorMessage = "Must be under 5 characters")]
    public string LastName { get; set; }
    [Range(18,50,ErrorMessage="Must be between 18 and 50")]
    public int Age { get; set; }
}
public sealed class CustomStartLetterMatch : ValidationAttribute, System.Web.Mvc.IClientValidatable 
{
    private const string _defaultErrorMessage …我使用的是带有标准WinForms的.NET C#,而不是WPF。
我有这种情况。我正在为一个月日历创建一个用户控件,类似于.NET,但具有更多功能。我有一个用户控件表单,其中填充了代表日期的按钮对象。这些按钮可以根据其状态(选择,鼠标悬停,周末...)涂上不同的颜色。
我希望它的工作方式是将按钮类扩展为接受确定颜色的状态,而不是从父类(用户控件)为它们着色。目前有10种颜色,我真的不想将用户控制代码与着色条件弄混。
另外,我想使用可浏览的设计器属性在设计时选择所有颜色。问题在于设计器仅显示用户控件类中定义的属性,而不显示其子级(按钮)。
有没有解决此问题的方法?简而言之,我想使用内部按钮属性来更改颜色,并希望能够在设计时使用设计器属性来选择颜色,而不是手动对其进行硬编码。
运用
<System.ComponentModel.TypeConverter(GetType(System.ComponentModel.ExpandableObjectConverter))> _
关于一个类的声明(它是另一个类的属性),由一个数字属性组成.
我简单地加载了这个类的一个实例......
PropertyGrid1.SelectedObject = oColumn
显然我不想在代码中手动构建propertygrid,我知道如何做到这一点.
但这是问题所在.根据属性的值,某些其他属性不应该是可见的,就像我使用了
<System.ComponentModel.Browsable(False)> _
属性声明中的属性.
无论如何以编程方式执行此操作,而无需手动处理属性网格的所有构建>
我创建了一个从ValidationAttribute派生的自定义验证器.我的undertsandng是它将为客户端脚本生成足够的元数据以自动验证(使用jquery.validate).自定义验证器在服务器端正常工作.但它不会在客户端激发错误消息.(其他默认验证器,如"StringLength"在客户端也正常工作.)我们如何纠正它?
public class Person
{
    [Required(ErrorMessage = "First name required")]
    public string FirstName { get; set; }
    [CustomStartLetterMatch("FirstName")]
    [StringLength(5,ErrorMessage = "Must be under 5 characters")]
    public string LastName { get; set; }
    [Range(18,50,ErrorMessage="Must be between 18 and 50")]
    public int Age { get; set; }
}
public sealed class CustomStartLetterMatch : ValidationAttribute
{
    private const string _defaultErrorMessage = " First letter of '{0}' must be same as first letetr of '{1}'";
    private string _basePropertyName;
    public CustomStartLetterMatch(string basePropertyName)
        : base(_defaultErrorMessage)
    { ….net ×3
asp.net-mvc ×3
c# ×3
asp.net ×2
jquery ×2
vb.net ×2
attributes ×1
children ×1
components ×1
design-time ×1
designer ×1
inheritance ×1
properties ×1
propertygrid ×1
required ×1