嗯我好像有问题,在我的主窗口我试图这样做:
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); //
}
Run Code Online (Sandbox Code Playgroud)
在我的另一个窗口,我有这个:
MainWindow.StudentID = (String)((Button)sender).Tag;
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
An object reference is required for the non-static field, method, or property 'WpfApplication4.MainWindow.StudentID.get'
Run Code Online (Sandbox Code Playgroud)
有谁知道我怎么解决这个问题?它适用于我的用户控件,但不适用于其他窗口?
我的主窗口实际上名为MainWindow,所以我可能有这个困惑.
您需要在MainWindow类的实例上设置StudentID.尝试
((MainWindow)Application.Current.MainWindow).StudentID = (String)((Button)sender).Tag;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6015 次 |
最近记录: |