Home > Blockchain >  c# WPF Mainwindow button is not recognized in UserControl code?
c# WPF Mainwindow button is not recognized in UserControl code?

Time:01-08

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;
  •  Tags:  
  • Related