In the xaml of the Mainwindow a button has been created with the name "btnDel" which is by default "Visibility = false". In my UserControlRDV.xaml.cs code I want to make that button visible with "MainWindow.btnDel.Visibility = true". Here I get an error CS0120 "An object reference is required for the nonstatic field, method, or property 'MainWindow.btnDel' ?
Please help!!
Thanks
CodePudding user response:
You can get a reference to the parent window of the UserControl using the Window.GetWindow method:
MainWindow mainWindow = Window.GetWindow(this) as MainWindow;
if (mainWindow != null)
mainWindow.btnDel.Visibility = Visibility.Visible;
