So i was wondering how i would make some kind of superwindow/superclass for my windows. The windows look the following:
The first picture shows how every single one of the windows would potentially look when pressed on one of the buttons. So each of these windows would have the same basic functionality but with some different returning objects which can be seen in the following code.
public partial class FlatsteelWindow : Window {
private string str;
private IList test;
public FlatSteel _returnObject { get; set; }
public double amount { get; set; }
public FlatsteelWindow(object inputObject) {
InitializeComponent();
_returnObject = inputObject as FlatSteel;
FetchList();
}
private void FetchList() {
test = MaterialLogic.GetFlatsteelList() as List<FlatSteel>;
foreach (FlatSteel flatSteel in test) {
flatsteelListView.Items.Add(flatSteel.Name);
}
}
private void flatsteelListView_PreviewMouseLeftButtonUp(object sender, RoutedEventArgs e) {
var item = (sender as ListView).SelectedItem;
if (item != null) {
_returnObject = flatsteelListView.SelectedItems as FlatSteel;
str = item.ToString();
amountTextbox.IsEnabled = true;
FindObject(str);
}
}
private void FindObject(string s) {
foreach (FlatSteel flatSteel in test) {
if (s.Equals(flatSteel.Name)) {
_returnObject = flatSteel;
}
}
}
private void submitButton_Click(object sender, RoutedEventArgs e) {
if (!string.IsNullOrEmpty(amountTextbox.Text)) {
amount = amountTextbox.Text.customParseToDouble();
this.Close();
}
else {
MessageBox.Show("Indtast venligst en værdi.");
}
}
}
This is the code for the shown Flatsteel window. Here is the code which creates the window:
private void flatsteelButton_Click(object sender, RoutedEventArgs e) {
FlatsteelWindow flatsteelWindow = new FlatsteelWindow(this);
flatsteelWindow.ShowDialog();
test = flatsteelWindow._returnObject;
amount = flatsteelWindow.amount;
if (test != null && amount != null) {
AddToGridView();
}
}
public FlatSteel test { get; set; }
private double amount { get; set; }
As we can see in this code the flatsteel object is needed where this method is invoked. The 6 different windows, which each are represented by the six buttons on the 2nd picture, each return an object to their type of material. So to make it clear what my question is: How do i make one superclass/superwindow that has all the same basic funtionality, from which i then can inherit from and add the needed functionality for the different returning objects?