I have two windows in my WPF app: a login window and an options window. Both have the same form with a user name and password field, as well as some other fields for providing credentials. I want some code that knows there will be a txt_userName TextBox available, for example, and can do things based on that. I was thinking I could make some kind of IHaveCredentialsForm interface and have both LoginWindow and OptionsWindow implement it, but when I tried, I got "'MyNamespace.LoginWindow' does not implement interface member 'MyNamespace.IHaveCredentialsForm.txt_userName'". Here's my interface so far:
interface IHaveCredentialsForm
{
TextBox txt_userName { get; set; }
}
I was thinking I got the error because LoginWindow is a partial class that inherits from Window. I can definitely access a TextBox called txt_userName inside the methods of LoginWindow, though I haven't explicitly defined such a property. It magically appeared from having a TextBox with that name in LoginWindow.xaml, I assume.
How can I go about DRYing this out? I already have a method for doing stuff with string values for the user name, password, etc., but it seems redundant to have two different classes that are passing in txt_userName.Text, pwb_password.Password, ...--the same arguments to the same method.
While I'm at it, how could I share a chunk of XAML (the credentials form) between two different windows?