嗯,我似乎有一个问题,在我的主窗口上我正在尝试做这个:
public static readonly DependencyProperty StudentIDProperty = DependencyProperty.Register("StudentID", typeof(String), typeof(LoginWindow), new PropertyMetadata(OnStudentIDChanged));
public string StudentID
{
get { return (string)GetValue(StudentIDProperty); }
set { SetValue(StudentIDProperty, value); }
}
static void OnStudentIDChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as LoginWindow).OnStudentIDChanged(e); //
}
在我的另一个窗口中,我有以下内容:
MainWindow.StudentID = (String)((Button)sender).Tag;
但是我收到了错误信息:
An object reference is required for the non-static field, method, or property 'WpfApplication4.MainWindow.StudentID.get'
有人知道我怎么能解决这个问题吗?它适用于我的用户控件,但不适用于其他窗口?
我的主窗口实际上被命名为MainWindow,所以我可能弄混了。