1)在多个视图之间传递数据的最佳方法是什么?
2)我有场景(MVVM C#):
MainWindow 中的 TextBox 和 Button 以及 Window1 中的 TextBlock,在单击按钮时(我正在使用 Icommand),MainWindow 的 TextBox 中的数据必须出现在 Window1 的 TextBlock 中?
视图模型库
public class ViewModelBase
{
public Commandclass commandclass { get; set; }
public ViewModelBase()
{
commandclass = new Commandclass(this);
}
private string fname;
public string vmname
{
get { return fname; }
set { fname = value; }
}
public void OnCommand()
{
Window1 w = new Window1();
/* How to bind ???*/
w.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
命令类.cs
public class Commandclass …Run Code Online (Sandbox Code Playgroud) 我正在使用 c# 紧凑框架和 vs2008。我面临 Lock 语句的问题。我的应用程序大部分时间都可以运行,但有时仍然挂起。
我尝试过这些
1) Lock(this)
2) lock (Core.Processor.Input.GPSIDInput.gps)
3) Monitor.TryEnter(Core.Processor.Input.GPSIDInput.gps);
try{}
finally{ Monitor.Exit(this); }
Run Code Online (Sandbox Code Playgroud)
为什么当我使用“try catch 块”时锁定失败时它不会出来。
GPS定位系统
[DllImport("coredll.dll")]
static extern int CloseHandle(IntPtr hObject);
public void Close()
{
try
{
lock (Core.Processor.Input.GPSIDInput.gps)
{
if (newLocationHandle != IntPtr.Zero){
CloseHandle(newLocationHandle);
newLocationHandle = IntPtr.Zero;
}......
}
}
catch (Exception excpt)
{
//stack trace
}
}
Run Code Online (Sandbox Code Playgroud)
GPSID输入.cs
namespace Core.Processor.Input
{
public class GPSIDInput
{
.......
public static Gps gps = new Gps();
public static void CloseGPS()
{
gps.Close();
}
} …Run Code Online (Sandbox Code Playgroud)