嗯,我似乎有一個問題,我的主窗口上我試圖做到這一點:對象引用需要非靜態字段,方法或屬性
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,所以我可能會有這個困惑。
想想這個:*哪個* MainWindow'做y你想改變'StudentID'嗎? – 2012-04-25 15:10:04
@JonSkeet。 *主要*當然。 :) – aquinas 2012-04-25 15:10:57
ahhh謝謝!這確實有道理! – 2012-04-25 15:12:45