0

I am creating a base window class that I want to use to store the common code for all our windows. I know all windows have text box and combo box that are used for the same purpose.

public abstract class WindowBase : Window
{

protected virtual void SaveTextBoxValue()
{
}

protected TextBox TextBoxNotes { get; set; }
}

public class MyWindow : WindowBase
{
public MyWindow()
{
InitializeComponent();
TextBoxNotes = txtNotes; // Now I have to set this in every inherited class
}
}

Is there a way to use the TextBox from the MyWindow classes without the need to set it in every conrete class?

st_stefanov
  • 1,147
  • 1
  • 10
  • 28
  • 1
    Create UserControl with both TextBox and ComboBox within. – Maximus Jul 14 '15 at 12:12
  • That is very good approach of course. Question is then, how would I position them in different locations for all windows... – st_stefanov Jul 14 '15 at 12:18
  • What do you mean diffrent locations? You define sceleton once and use it repeatedly. – Maximus Jul 14 '15 at 12:23
  • Well, in all windows the text box can have different locations. Next to label, on top of the window, on bottom, on the left side. Then the combo can be anywhere as well. With user control they will have to be static from each other. – st_stefanov Jul 14 '15 at 12:25
  • 1
    You can add properties indicating TextBox and Combobox position, respectively. – Maximus Jul 14 '15 at 12:30
  • Thank you. That seems like a solution. I can declare all shared controls in the User Control and reuse all of them instead writing the same ones in every XAML file. – st_stefanov Jul 14 '15 at 12:39
  • Hold on I am going to summarize it in separate answear. – Maximus Jul 14 '15 at 12:41
  • I have closed your question as a duplicate. See my answer in the linked question to better understand how to create composable, reusable UIs in WPF. If my answer does not satisfy your needs, please feel free to [ask a new question](http://stackoverflow.com/questions/ask). – Federico Berasategui Jul 14 '15 at 14:29

1 Answers1

0

In the constructor of the abstract class set it by finding the first textbox in the window or whatever way u want to identify the text box.