Tag: 数据绑定

将对象列表绑定到图表

我有一个对象列表: List MyList = new List(); MyClass包含实时更新的Properties Dtm和LastPrice public class MyClass { int dtm; double lastPrice = 0; public int Dtm { get { return dtm; } set { dtm = value; } } public double LastPrice { get { return lastPrice; } set { lastPrice = value; } } } 我现在想要一个列在列表中的图表,每次属性更改时都会自动更新。 有什么想法怎么做? 谢谢

改变多边形的点数

解决方案 窗口拖动的动态余量 所以我试图让我的多边形在窗口移动时移动。 我有; private void ResetPolygon(Point Point1, Point Point2, Point Point3) { SpeechPoly.Points.Clear(); ObservableCollection myPointCollection = new ObservableCollection(); myPointCollection.Add(Point3); myPointCollection.Add(Point2); myPointCollection.Add(Point1); foreach (Point p in myPointCollection) { SpeechPoly.Points.Add(p); } } private void Window_LocationChanged(object sender, EventArgs e) { if (this.IsLoaded) { Point Point1 = new Point(newPoint3); Point Point2 = new Point(newPoint2); Point Point3 = new […]

自定义StronglyTyped BindingSource项目添加

我想自定义添加一个新项目到BindingSource (所有强类型),如下面的MSDN文章所述: 如何:使用Windows窗体绑定源自定义项目添加 下面的代码导致InvalidOperationException :添加到BindingSource列表的对象必须都是相同的类型。 此外,对象myTypesBindingSource.Current似乎是一个DataRowView ,里面有我的相关行。 如何自定义强类型BindingSource ? private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.someDataSet = new myDB.SomeDataSet(); this.myTypesBindingSource = new System.Windows.Forms.BindingSource(this.components); this.myTypesTableAdapter = new myDB.SomeDataSetTableAdapters.myTypesTableAdapter(); this.tableAdapterManager = new myDB.SomeDataSetTableAdapters.TableAdapterManager(); this.myTypesBindingNavigator = new System.Windows.Forms.BindingNavigator(this.components); this.someIntValueTextBox = new System.Windows.Forms.TextBox(); // someDataSet this.someDataSet.DataSetName = “SomeDataSet”; this.someDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; // myTypesBindingSource // As generated: // […]

WPF MVVM后台打印数据绑定问题

我正在使用wpf / mvvm开发销售点应用程序。 在交易生命周期的许多部分中,将在后台打印收据。 我已经使用其他示例在后台生成和打印收据。 我在后台打印UserControl,一切看起来都很棒。 然后我为控件创建了ViewModel,因此它可以加载要打印的事务。 我从2个基本文本框开始 – 文本标题“客户收据”和顶部标题“打印在:MM / dd / yy hh:mm tt”。 这是调试器在按下打印按钮时显示生命周期的方式: 创建新的控件实例。 创建ViewModel的新实例 设置INPC属性的文本 在Control上运行一个小节以获得所需的预打印尺寸 加载打印对话框并检索名称打印队列 缩放控件的大小以适合收据纸(不应该为我当前选择的打印机缩放,因为ImageArea宽度设置与我的UC相同) 根据“新”缩放图像大小重新测量和排列网格 调用PrintDialog.PrintVisual – 发送UserControl 打印机吐出收据 – 没有数据绑定文本 然后,我的调试器进入get {return _HeaderText; 部分代码 – 控件已经打印完毕。 有没有办法在控件发送到打印机之前强制控制数据绑定,而无需在面板中加载控件并使其可见? 我希望能够例如刷信用卡并让它在背景中打印带有签名行的收据,从一个小的弹出窗口询问CC详细信息(或滑动)。 有没有更好的方法来实现这一目标? PrintReceipt方法: ClientReceiptView control = new ClientReceiptView(Message); System.Windows.Controls.PrintDialog printDlg = new System.Windows.Controls.PrintDialog(); PrintQueue ReceiptPrinter = new LocalPrintServer().GetPrintQueue(“CITIZEN […]

将UserControl绑定到自己的dependencyProperty不起作用

我有一个问题,当我将该对象设置为数据绑定时,我无法创建使用自定义对象属性的用户控件。 试着解释一下我的意思是代码。 自定义对象: public class MyObj { public string Text { get; set; } public MyObj(string text) { Text = text; } } 用户控制代码背后: /// /// Interaction logic for MyControl.xaml /// public partial class MyControl : UserControl { public static readonly DependencyProperty ObjectProperty = DependencyProperty.Register(“Object”, typeof (MyObj), typeof (MyControl), new PropertyMetadata(default(MyObj))); public MyObj Object { […]

使用c#在asp.net中排序列表和下拉列表

我有一个方法,它返回一个sortedList,我想将它数据源到Dropdownlist。 我在用 DropDownList1.DataSource=stList; DropDownList1.DataValueField=stList.ContainsValue(); DropDownList1.DataTextField=stList.ContainsKey(); DropDownList1.DataBind(); 但它给出了一个错误:containsKey和containsValue没有重载方法。 如何在下拉列表中填充此已排序的表?

如何消除WPF输出窗口中的绑定“信息” – 无法使用绑定检索值

我正在编写一个WPF应用程序,性能有点慢,所以我试图解决它。 当我跑步时,我会收到大量这些类型的消息: System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=(0); DataItem=null; target element is ‘Control’ (Name=”); target property is ‘Visibility’ (type ‘Visibility’) System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; […]

更改数据源时更新绑定控件的更好方法

问题。 我有一个数据绑定到我的表单上的属性中的字段,用于表单上的大量文本框。 我不仅更改属性中的字段值,还更改整个属性(重置为以前保存的默认值)。 我想做的是这样的事情: ((CurrencyManager)BindingContext[Row]).Refresh(); 不起作用, BindingContext[Row]是一个PropertyManager ,而不是CurrencyManager ,并且没有刷新方法。 PushData()受保护且无法访问。 我也试过调用this.Refresh() ,并在每个控件上单独调用c.Refresh …现在怎么办? 这是我目前使用的代码: private void btnReset_ButtonClicked(object sender, EventArgs e) { Row = ResetRow.Clone();//use clone to break the reference, dont want to be updating the ResetRow when Row fields change. foreach (Control c in pnlBody.Controls) if (c.DataBindings.Count > 0) c.DataBindings.Clear(); DataBindandSet();//re-apply all the databindings (50) […]

将DataSource属性添加到自定义WinForms控件

我想将复杂的数据绑定添加到我的自定义winforms控件中,所以我可以执行以下操作: myControl.DisplayMember = “Name”; myControl.ValueMember = “Name”; myControl.DataSource = new List(); 有谁知道必须实现什么接口等来实现这一目标? 我已经看过它,我发现的只是IBindableComponent ,但这似乎是简单绑定而不是复杂绑定。

多选WinForms列表框中的双向绑定?

我有一个项目,我们从一组对象加载一个多选列表框。 我有另一个实体对象,它有一个我想以某种方式绑定到SelectedItems的集合。 有没有办法使用对象绑定源或某种绑定源而不编写代码? 当然,我可以遍历集合并获取所选项目,但我更喜欢使用Windows数据绑定更干净地完成它。 这可能吗?