Tag: 模板

如何更改WPF中绑定选项的默认值?

在我当前的项目中,我使用了几个文本框控件,其内容由来自数据库的对象填充。 该对象使用validation来validation文本的正确插入。 当我想显示validation错误(即文本有多个字符)时,我必须向text属性添加一些绑定选项,如下一行所示: 是否可以创建模板或样式或任何将最后三个选项(ValidatesOnDataErrors,NotifyOnValidationError,UpdateSourceTrigger)的默认值更改为上面代码中的值? 文本框控件应该如下所示:

如何在包装包含向量的模板类时让SWIG应用模板?

我试图使用SWIG来包装(在C#中)一些包含模板类的c ++代码,该模板类本身包含了一个std::vector 。 我已经在互联网上看到了关于如何为矢量类型声明模板的各种参考,但是无法使用额外的抽象层。 这就是我在interface.i文件中所做的事情,例如: // interface.i file %module myNamespaceWrapper %{ #include “myVector.h” %} %include “myVector.h” %include “std_string.i” %include “std_vector.i” namespace std { %template(vector_MyType) vector; %template(vector_Int) vector; } namespace myNamespace { %template(myVectorMyType) myVector; %template(myVectorInt) myVector; } 虽然这似乎可以自己正确地创建相应的C#类型,但是我试图定义的std :: vector模板不会应用于其他在内部使用它们的类,通过头文件包含它们。 为了告诉你我的意思,有一个c ++类,如: // myVector.h namespace myNamespace { template class myVector { private : std::vector vect; public […]

如何制作深拷贝字典模板

我有以下方法来制作字典的deep copy : public static Dictionary deepCopyDic(Dictionary src) { //Copies a dictionary with all of its elements //RETURN: // = Dictionary copy Dictionary dic = new Dictionary(); for (int i = 0; i < src.Count; i++) { dic.Add(src.ElementAt(i).Key, new MyClass(src.ElementAt(i).Value)); } return dic; } 我想知道,我可以以某种方式将其变成模板吗? 我需要MyClass作为模板。

Visual Studio项目模板:替换为项目名称

我正在尝试在Visual Studio 2013中为EF Code-First上下文类创建项模板。 除了我想要一个指向当前项目中的命名空间的using语句之外,我已经完成了所有工作。 例如,在ProjectName .Contexts中创建模板项的实例时,using语句将为: 使用ProjectName .Models 问题是我找不到替换项目模板中的部分的方法。 尽管我可以确定,$ projectname $和$ safeprojectname $仅适用于项目模板,而不适用于项目模板。 我的模板如下: using System; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using $safeprojectname$.DAL.Models; // This is the problem line namespace $rootnamespace$ { public class $safeitemrootname$ : DbContext { // Constructors ======================================================= public $safeitemrootname$() : base(“$safeitemrootname$”) { } // DBSets ============================================================= // public DbSet Companies […]

ControlTemplate for ScrollBar仅适用于DataGrid

你好我有一个ScrollBar模板如下 – 只显示相关部分: <Border…. 现在矩形部分: 我只希望它出现在DataGrids上或者我希望这个进入ControlTemplate只能在DataGrids的ScrollBars上运行。 任何帮助将不胜感激! 谢谢!

C#项目模板和项目名称的变量?

我的大部分代码都包含三个相关的类,一个基于一个名为IImplementation的接口,一个Execute方法(以帮助强制执行单一责任)以及一个响应和上下文类。 我厌倦了这个,它费力,重复和耗时,所以今天我决定写一个C#项目模板。 模板文件和.vstemplate文件如下所示: Implmentation.vstemplate Implementation Genertates a skeletal concrete IImplementation class complete with Response and Context classes. Class.ico 74206442-81cb-4328-afc8-08c40fb5d3e7 CSharp 2.0 1 Class.cs System Implementation.cs Response.cs Context.cs Microsoft.VisualStudio.Web.Application, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Microsoft.VisualStudio.Web.Application.WATemplateWizard /> Implementation.cs using System; using $safeprojectname$.Implementation.Attibutes; using $safeprojectname$.Implementation.Interfaces; namespace $rootnamespace$ { [AutofacRegisterImplementation] public class $classname$ : IImplementation { #region Execute public $fileinputname$Response Execute($fileinputname$Context […]

从ItemsControl中的模板中获取项目

我有一个ItemsControl,其中填充了一些ViewModel类的可观察集合,如下所示: 效果很好,看起来很棒,但我似乎无法弄清楚如何让“ClickHandler”知道由数据模板表示的类“MyViewModel”。 看哪! private void ClickHandler(object sender, RoutedEventArgs e) { // The ‘sender’ is the button that raised the event. Great! // Now how do I figure out the class (MyViewModel) instance that goes with this button? }

ListViewItem与CheckBox IsChecked绑定到ViewModel

我有一个带有DataTemplate的ListView,用于为每个ListViewItem显示一个Checkbox。 ItemsSource(“TableNames”)在ViewModel中被解除,如下所示: private ObservableCollection _TableNames = new ObservableCollection(); public ObservableCollection TableNames { get { return _TableNames; } set { _TableNames = value; OnPropertyChanged(“TableNames”); } } public class Item { public bool IsSelected { get; set; } public string Name { get; set; } public override string ToString() { return this.Name; } } 如何将Checkbox中的IsChecked绑定到Item.IsSelected属性? 我的代码不起作用。

“类,其中T:Enum”不起作用

可能重复: 创建将T限制为枚举的通用方法 我们有什么理由不能在C#中做到这一点吗? 而且,如果可能的话,我该怎么做类似的事情! 我想要的是 : public class ATag where T : enum { [Some code ..] } public class classBase where T : enum { public IDictionary tags { get; set; } } 所以,当它到了调用它的时候,我只能得到一个我的枚举值。 public class AClassUsingTag : classBase { public void AMethod(){ this.tags.Add(PossibleTags.Tag1, “Hello World!”); this.tags.Add(PossibleTags.Tag2, “Hello Android!”); } } public enum PossibleTags […]

WPF DataTemplate和Binding

我继续用MSDN的代码理解MVVC,我有一个问题。 在.xaml中,它们有一个显示在屏幕上的命令列表。 从这里,我了解DataContext已设置(此处未显示),它将显示命令集合。 我不明白的是你可以在下面看到的CommandsTemplate: pou 如何创建绑定? 这段代码如何告诉从集合中的对象检查属性Command和DisplayName? 它来自ItemsSource吗? 如果是,我不明白为什么它只在{Binding}。 任何人都可以向我解释一下DataTemplate绑定如何从ContentTemplate运行?