具有相同功能的多个窗口

时间:2015-11-24 19:53:03

标签: c# wpf forms

所以我想知道如何为我的窗口制作某种超级窗口/超类。窗口如下所示:

Window with functionality Buttons for the windows

第一张照片显示按下其中一个按钮时,每个窗口的每个窗口都有可能显示。因此,每个窗口都具有相同的基本功能,但具有一些不同的返回对象,可以在以下代码中看到。

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.");
        }
    }
}

这是显示的Flatsteel窗口的代码。 以下是创建窗口的代码:

        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; }

正如我们在此代码中所看到的,在调用此方法时需要flatsteel对象。 6个不同的窗口,每个窗口由第二张图片上的六个按钮表示,每个窗口都返回一个对象到它们的材料类型。所以说清楚我的问题是什么: 我如何创建一个具有所有相同基本功能的超类/超级窗口,然后我可以从中继承并为不同的返回对象添加所需的功能?

0 个答案:

没有答案