Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
371 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

824 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