【发布时间】:2018-05-26 20:34:53
【问题描述】:
我正在使用 UI 页面来表示秤的重量值。
c# 代码不断从真实刻度设备中读取刻度值
我必须向 UI(wpf) 屏幕显示价值。
当比例值改变时 UI 屏幕(scaleShow.xaml.cs) 需要知道
比例值已更改。
所以我正在考虑使用该事件让 scaleShow.xaml.cs 页面知道。
但不知道如何实现它
MainWindow.xaml.cs
this.Dispatcher.BeginInvoke(new Action(delegate()
{
this.ctTbWeight.Text = this.curWeight + " kg";
//when this.curWeight value changed I want to the scale.xaml.cs page notice it
}
scale.xaml.cs
public scale(EventHandler handler, ILog logger, ObservableDictionary<string, LanguageChangedImpl> language, Stopwatch elapse)
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(_PageLoaded);
this.tel = new Telegram();
this.tel.Name = this.GetType().Name;
this.pagingMachine = handler;
this.def = new Defines();
this.log = logger;
this.lang = language;
this.elapseTime = elapse;
}
我尝试在 MainWindow.cs 中创建事件,但不确定如何使用它(如果它的按钮单击它很明显可以使用)
public event EventHandler getWeight;
protected virtual void OngetWeight(EventArgs e)
{
EventHandler handler = getWeight;
if (handler != null)
{
handler(this, e);
}
}
请给我一些指导,让缩放页面注意到缩放值已更改。如果您需要更多信息,请告诉我。
【问题讨论】: