以wpf为前台 c#为后台
我在界面一的后台计算出数据aa,bb
希望在界面二展示
求运用c#中的类来解决
看你问了几次了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace WpfApplication1
{
class Dataabb:INotifyPropertyChanged
{
protected void ech<T>(ref T propValue, T newValue, string propName = "");
int m_aa;
public int aa
{
get { return m_aa; }
set
{
ech(ref m_aa, value);
}
}
int m_bb;
public int bb
{
get { return m_bb; }
set
{
ech(ref m_bb, value);
}
}
}
}
界面2定义一个公共变量,打开界面2的时候把界面1的值赋值给这个变量,就获取到界面1的值了。
更详细供参考
Dataabb数据模型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace WpfApplication1
{
public class Dataabb:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void ech<T>(ref T propValue, T newValue, [CallerMemberName] string propName = "")
{
if (object.Equals(propValue, newValue)) return;
propValue = newValue;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
int m_aa;
public int aa
{
get { return m_aa; }
set
{
ech(ref m_aa, value);
}
}
int m_bb;
public int bb
{
get { return m_bb; }
set
{
ech(ref m_bb, value);
}
}
}
}
Window1代码
public partial class Window1 : Window
{
public Dataabb dataabb = new Dataabb();
public Window1()
{
InitializeComponent();
dataabb.aa = 34;
dataabb.bb = 55;
Binding bdaa = new Binding() { Path = new PropertyPath("aa"), Source = dataabb };
textBox1.SetBinding(TextBox.TextProperty, bdaa);
textBox3.SetBinding(TextBox.TextProperty, bdaa);
Window2 win2 = new Window2();
win2.textBox1.SetBinding(TextBox.TextProperty, bdaa);
Binding bdbb = new Binding() { Path = new PropertyPath("bb"), Source = dataabb };
textBox2.SetBinding(TextBox.TextProperty, bdbb);
win2.textBox2.SetBinding(TextBox.TextProperty, bdbb);
win2.Show();
}
}
运行效果