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
363 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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