如何在WPF C#中进行数据绑定(从combox中选择) [英] How do data binding in WPF C# ( select from combox )

查看:1270
本文介绍了如何在WPF C#中进行数据绑定(从combox中选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Wpf C中进行装订#



我要做绑定



当选择项目时形成组合框(项目顶部,底部,左侧,右侧)





我有6个文本框来更新值(最小和最大显示)但它没有更新。



需要一些帮助..



提前致谢..



我尝试过:



公共部分课TeachMenu:Page

{



private ObservableCollection< parampos> Param;

public TeachMenu()

{

InitializeComponent();





Param1 =新ObservableCollection< posparam>()

{

新PosParam(){R_min = 1,R_max = 255,G_min = 1,G_max = 255,B_min = 1,B_max = 255},

新PosParam(){R_min = 2,R_max = 255,G_min = 2,G_max = 255,B_min = 2,B_max = 255},

新PosParam(){R_min = 3,R_max = 255,G_min = 3,G_max = 255,B_min = 3,B_max = 255},

new PosParam(){R_min = 4,R_max = 255,G_min = 4,G_max = 255,B_min = 4,B_max = 255}

};

TabPositioning.DataContext = Param;



}



公共类Param

{



public int R_min {get => r_min; set => r_min = value; }

public int R_max {get => r_max时; set => r_max =值; }

public int G_min {get =>将G_min; set => g_min = value; }

public int G_max {get => g_max; set => g_max =值; }

public int B_min {get => b_min; set => b_min = value; }

public int B_max {get => b_max; set => b_max =值; }

public double Row1 {get => ROW1; set => row1 = value; }

public double Col1 {get => COL1; set => col1 =值; }

public double Row2 {get => 2行; set => row2 = value; }

public double Col2 {get => COL2; set => col2 =值; }



public enum PosFrame

{

Frame,

Top,

底部,

剩下,

正确

}

private int r_min;

private int r_max;

private int g_min;

private int g_max;

private int b_min;

private int b_max;



private double row1;

private double col1;

private double row2;

private double col2;



}

How to do binding in Wpf C#

I tring to do binding

when select item form combobox( Item Top,Bottom,Left,Right)


I have 6 text box to update value (min and max display) but its not updating.

Need some one help..

Thanks in advance..

What I have tried:

public partial class TeachMenu : Page
{

private ObservableCollection<parampos> Param;
public TeachMenu()
{
InitializeComponent();


Param1 = new ObservableCollection<posparam>()
{
new PosParam() { R_min = 1, R_max = 255, G_min = 1, G_max = 255, B_min = 1, B_max = 255 },
new PosParam() { R_min = 2, R_max = 255, G_min = 2, G_max = 255, B_min = 2, B_max = 255 },
new PosParam() { R_min = 3, R_max = 255, G_min = 3, G_max = 255, B_min = 3, B_max = 255 },
new PosParam() { R_min = 4, R_max = 255, G_min = 4, G_max = 255, B_min = 4, B_max = 255 }
};
TabPositioning.DataContext = Param;

}

public class Param
{

public int R_min { get => r_min; set => r_min = value; }
public int R_max { get => r_max; set => r_max = value; }
public int G_min { get => g_min; set => g_min = value; }
public int G_max { get => g_max; set => g_max = value; }
public int B_min { get => b_min; set => b_min = value; }
public int B_max { get => b_max; set => b_max = value; }
public double Row1 { get => row1; set => row1 = value; }
public double Col1 { get => col1; set => col1 = value; }
public double Row2 { get => row2; set => row2 = value; }
public double Col2 { get => col2; set => col2 = value; }

public enum PosFrame
{
Frame,
Top,
Bottom,
Left,
Right
}
private int r_min;
private int r_max;
private int g_min;
private int g_max;
private int b_min;
private int b_max;

private double row1;
private double col1;
private double row2;
private double col2;

}

推荐答案

Binding适用于属性,而不是字段。所以更改:

Binding works with Properties, not Fields. So change:
private ObservableCollection<parampos> Param;



with


with

public ObservableCollection<parampos> Param {get; set;}



此外,清除 ObservableCollection ,始终使用 Clear()方法,而不是


Also, to clear an ObservableCollection, always use the Clear() method and not

new ObservableCollection<...>();

作为后者打破绑定。



您可以在此处阅读更多相关信息:数据绑定(WPF)| Microsoft Docs [ ^ ]

as the latter with break the binding.

You can read more about this here: Data Binding (WPF) | Microsoft Docs[^]






我附加了代码..当选择组合框项目.. 。滑块和文本框值应该改变。谢谢你的帮助..



Binding - Google Drive [ ^ ]


这篇关于如何在WPF C#中进行数据绑定(从combox中选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆