Hi,
you must declare the List as a property. To access the list from an other class you must give an instance from your List to the other class.
The classes where you must give an instance from your List to access it:
namespace ReportsUIScreens
{
public partial class FilterHistory : ChildWindow
{
private List<filterHistory> histList;
public FilterHistory(List<filterHistory> histListLink)
{
InitializeComponent();
histList = histListLink;
this.HistoryList.ItemsSource=histList;
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
...
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
...
}
}
}
namespace ReportsUIScreens
{
public partial class SaveFilterHistory : ChildWindow
{
private List<filterHistory> histList;
public SaveFilterHistory(List<filterHistory> histListLink)
{
InitializeComponent();
histList = histListLink;
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
histList.Add(new filterHistory(){FilterName="Filter1", Date=new DateTime(2011, 04, 30)});
this.DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
}
}
The class with the List:
namespace ReportsUIScreens
{
public partial class Screen_2 : UserControl
{
private List<filterHistory> hist {get;set;}
public Screen_2()
{
InitializeComponent();
history();
}
private void viewFilterHistory(object sender, System.Windows.RoutedEventArgs e)
{
FilterHistory history = new FilterHistory(hist);
history.Show();
}
private void saveFilterHistory(object sender, System.Windows.RoutedEventArgs e)
{
SaveFilterHistory history = new SaveFilterHistory(hist);
history.Show();
}
public void history()
{
hist = new List<filterHistory>()
{
new filterHistory(){FilterName="Filter1", Date=new DateTime(2010, 12, 20)},
new filterHistory(){FilterName="Filter2", Date=new DateTime(2011, 04, 20)}
};
}
}
}
you must pull out the filterHistory class out of your partial class and paste it simply in the namespace or in a separate .cs file
public class filterHistory
{
public string FilterName { get; set; }
public DateTime Date { get; set; }
}
Hope it helps