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
359 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now