bickes0724
asked on
WPF, C# - Is it Possible to Set the ItemsSource of a Control in a Different Class From A Static Method?
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:
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!
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);
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!
ASKER
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.
The event approach sounds promising, I am not positive how to implement it.
Check out these articles:
http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
http://osix.net/modules/article/?id=685
http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
http://osix.net/modules/article/?id=685
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, did the events approach work?
ASKER
Thanks
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.