I have a DataGrid in MainWindow.xaml called "DG_Scanner", I need to be able to send data to it from a static method called "printService" that is in MainWindow.xaml.cs, it does not allow me to communicate with the outside because it is static.
MainWindow code:
public MainWindow()
{
InitializeComponent();
string serviceType = "_http._tcp";
ServiceBrowser serviceBrowser = new ServiceBrowser();
serviceBrowser.ServiceAdded += onServiceAdded;
serviceBrowser.ServiceRemoved += onServiceRemoved;
serviceBrowser.ServiceChanged += onServiceChanged;
serviceBrowser.StartBrowse(serviceType);
}
static void onServiceChanged( object sender, ServiceAnnouncementEventArgs e)
{
printService(null ,'~', e.Announcement);
}
static void onServiceRemoved(object sender, ServiceAnnouncementEventArgs e)
{
printService(null ,'-', e.Announcement);
}
static void onServiceAdded( object sender, ServiceAnnouncementEventArgs e)
{
printService(null ,'+', e.Announcement);
}
static void printService(MainWindow window,char startChar, ServiceAnnouncement service)
{
y = new List<Data>();
y.Add(new Data() { hostname = service.Hostname });
y.Add(new Data() { maccaddress = " " });
y.Add(new Data() { name = " " });
y.Add(new Data() { port = " " });
window.DG_scanner.Items.Add(y);
}
The list is sent to a DataGrid, that data should be displayed in the MainWindow.xaml when executed
you should define
then from the window you pass the instance of that window, if you call this from
MainWindow
you would useBy using the
this
fromMainWindow
you refer to the instance of that windowNote: I put the "varXX" because I don't know what value you assign to it