Solved

WPF, C# - Is it Possible to Set the ItemsSource of a Control in a Different Class From A Static Method?

Posted on 2011-03-08
6
362 Views
Last Modified: 2012-06-21
Is it Possible to Set the ItemsSource of a Control in a Different Class From A Static Method?

I have an addin (class 1) that allows you to view and filter table records. Below the filters is a ListView control that displays saved queries and a button to open a window that manages those queries. In the window (class 2) you can add, edit, and delete queries. After the user saves changes, I would like to update the ListView control in class 1 from class 2. If possible I would like to use the following syntax:


//Class 1 Static Method:
public static void SetListViewItemsSource(ObservableCollection<Query> queries)
{
      this.listViewControl.ItemsSource = queries;
}

// To Change ItemsSource From Class2:
Class1.SetListViewItemsSource(queryCollection);

Open in new window


I know this approach is not possible because you cannot use the "this" keyword in a static method. Is there an alternative, WITHOUT having to create and instance of Class1??

Thanks!
0
Comment
Question by:bickes0724
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:dimaj
ID: 35069768
This might be a dumb question...
How are you planning to see the control if you are not instantiating Class1?

As far as an approach goes, take a look at events. You could pass data via EventArgs when a query changes.
0
 

Author Comment

by:bickes0724
ID: 35070178
Class 1 is already instantiated because it is loaded first. The popup window loads from a button clicked on the Class 1. So, when an update to the user saves changes, in Class 2, I just want to copy the changes/collection to the ItemsSource in Class 1.

The event approach sounds promising, I am not positive how to implement it.
0
 
LVL 7

Expert Comment

by:dimaj
ID: 35070418
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Accepted Solution

by:
bickes0724 earned 0 total points
ID: 35071210
Thank you for your help!!!
0
 
LVL 7

Expert Comment

by:dimaj
ID: 35071797
So, did the events approach work?
0
 

Author Closing Comment

by:bickes0724
ID: 35120641
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Allow space in this pattern 2 47
C# Offline Apllication 5 54
Host asp.net pages 5 25
C# parent child form 5 16
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now