在主視窗的 xaml 中創建了一個名為“btnDel”的按鈕,默認情況下為“Visibility = false”。在我的 UserControlRDV.xaml.cs 代碼中,我想使用“MainWindow.btnDel.Visibility = true”使該按鈕可見。在這里我收到一個錯誤 CS0120 “非靜態欄位、方法或屬性 'MainWindow.btnDel' 需要物件參考?
請幫忙!!
謝謝
uj5u.com熱心網友回復:
您可以UserControl使用以下Window.GetWindow方法獲取對父視窗的參考:
MainWindow mainWindow = Window.GetWindow(this) as MainWindow;
if (mainWindow != null)
mainWindow.btnDel.Visibility = Visibility.Visible;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/405855.html
標籤:
