Tag: 数据绑定

winForms + DataGridView绑定到List <T>

我试图将一个List<T>绑定到一个DataGridView控件,我没有任何运气创build自定义绑定。 我努力了: gvProgramCode.DataBindings.Add(new Binding("Opcode",code,"Opcode")); 它抛出一个exception,说这个属性名没有find。 问题栏的名称是“操作码”。 List<T>属性的名称是Opcode。 回答编辑 :问题是,我没有在我的课作为属性,只是公共领域的可绑定领域…显然它不反映在领域,只是属性。

为什么我不能在ComboBox中select一个空值?

在WPF中,从ComboBox中select(使用鼠标)“null”的值似乎是不可能的。 编辑为了澄清,这是.NET 3.5 SP1。 这里有一些代码来展示我的意思。 首先,C#声明: public class Foo { public Bar Bar { get; set; } } public class Bar { public string Name { get; set; } } 接下来,我的Window1 XAML: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <ComboBox x:Name="bars" DisplayMemberPath="Name" Height="21" SelectedItem="{Binding Bar}" /> </StackPanel> </Window> 最后,我的Window1类: public partial class Window1 : […]

如何将XSD转换为Python类

我只想知道是否有一个程序可以将JAXB用于Java的XSD文件转换为Python类?

在TextBlock中使用绑定对文本进行硬编码

在WPF中,有没有办法让TextBlock的Text属性包含硬编码的文本和特定的绑定? 我想到的是以下几点(当然,下面不会编译) : <TextBlock Text="Number of Fans: {Binding Artist.Fans.Count}"></TextBlock>

何时使用WPF绑定path?

我已经看到了很多WPF绑定的例子,并且在学习MVVM的许多不同的地方使用了这个特性,但是对于我来说似乎很不一致的是当你在绑定string中指定“Path =”作为简单的键入要绑定的属性。 例如,以下XAML属性之间的function区别是什么: DataMemberBinding="{Binding SomeProperty}" DataMemberBinding="{Binding Path=SomeProperty}"

保存之前的WPF数据绑定

在我的WPF应用程序中,我有一些数据绑定文本框。 这些绑定的UpdateSourceTrigger是LostFocus 。 该对象使用“文件”菜单进行保存。 我遇到的问题是,可以在文本框中input一个新的值,从文件菜单中select保存,并且永远不会保留新值(在文本框中可见的值),因为访问菜单不会从文本框中移除焦点。 我怎样才能解决这个问题? 有没有办法强制一个页面中的所有控件进行数据绑定? @palehorse:好点。 不幸的是,我需要使用LostFocus作为我的UpdateSourceTrigger,以支持我想要的validationtypes。 @dmo:我已经想到了。 然而,对于一个相对简单的问题来说,它似乎是一个非常不合理的解决scheme。 另外,它要求在页面上有一些控件总是可见的以获得焦点。 我的应用程序是选项卡,但是,所以没有这样的控制很容易出现。 @Nidonocu:使用菜单没有移动焦点从TextBox混淆了我的事实。 然而,这是我所看到的行为。 以下简单的例子演示了我的问题: <Window x:Class="WpfApplication2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.Resources> <ObjectDataProvider x:Key="MyItemProvider" /> </Window.Resources> <DockPanel LastChildFill="True"> <Menu DockPanel.Dock="Top"> <MenuItem Header="File"> <MenuItem Header="Save" Click="MenuItem_Click" /> </MenuItem> </Menu> <StackPanel DataContext="{Binding Source={StaticResource MyItemProvider}}"> <Label Content="Enter some text and then File > Save:" /> <TextBox […]

WPF DataBinding:可空的Int仍然得到validation错误?

我有一个文本框的数据绑定到一个可空的int通过代码。 如果我从文本框中删除数据,它会给我一个validation错误(红色边框)。 这是我的绑定代码: ZipBinding = new Binding("Zip"); ZipBinding.Source = Address; zipTextBox.SetBinding(TextBox.TextProperty, ZipBinding); public Int32? Zip { get { … } set { … } } 它清楚地标记为Nullable所以为什么WPF想给我一个validation问题,当我清除文本框?

Angular 2checkbox双向数据绑定

我是相当新的Angular2,我有一个小问题:在我的login组件HTML中,我有两个checkbox,我想以两种方式绑定到login组件TypeScript的数据绑定。 这是HTML: <div class="checkbox"> <label> <input #saveUsername [(ngModel)]="saveUsername.selected" type="checkbox" data-toggle="toggle">Benutername speichern </label ></div> 这是Component.ts: import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Variables } from '../../services/variables'; @Component({ selector: 'login', moduleId: module.id, templateUrl: 'login.component.html', styleUrls: ['login.component.css'] }) export class LoginComponent implements OnInit { private saveUsername: boolean = true; private […]

如何将List <CustomObject>绑定到WPF DataGrid?

我是WPF的新手,想做一些基本的数据绑定。 我有一个CustomObject的列表,并希望将其绑定到DataGrid。 MainWindow.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); List<ArticleItem> list = […]

什么时候应该打开和closures连接到SQL Server

我有一个简单的静态类,其中有几个方法。 每个方法打开一个SqlConnection,查询数据库并closures连接。 这样,我确信我总是closures与数据库的连接,但另一方面,我不喜欢总是打开和closures连接。 下面是我的方法的例子。 public static void AddSomething(string something) { using (SqlConnection connection = new SqlConnection("…")) { connection.Open(); // … connection.Close(); } } 考虑到方法是在一个静态类,我应该有一个静态成员包含单个SqlConnection? 我应该如何以及何时放弃它? 什么是最佳实践?