I've seen a few different pages here on SO that discuss what I'm after, but I think my case is different enough to warrent a new question here. So I have a base class with no XAML.
public abstract class AbstractConfigWindow : System.Windows.Window
{
public AbstractConfigWindow()
{
this.WindowState = System.Windows.WindowState.Maximized;
this.WindowStyle = System.Windows.WindowStyle.None;
this.SetResourceReference(System.Windows.Window.BackgroundProperty, "formBackground");
}
private bool locked = false;
public bool Locked
{
get { return locked; }
set { locked = value; }
}
}
I have a 3 UserControls that I created. They have a background image of a computer, and 4 common buttons (unrelated to question, just details).
I have 2 Windows that extend the AbstractConfigWindow. One is for Landscape view and the other Portrait. (Not sure if this is the best way of doing it, but it works for me) I placed those 3 UserControls in each of the 2 Child Window classes. Since at one time both of those Windows were just simple Windows it was not a problem. Well now that I have this base class I want to put all the common things (such as the Window state, style background..etc, etc) in the base class. This would include the 3 user controls (which there will be more of those added as this program gets bigger) My first thought is to programmatically add new instances into a Grid
.. and then just put that grid where I need to in each of the 2 windows. I hate how fragile it is though. This is a small example of what one of the 2 windows looks like.
<local:AbstractConfigWindow x:Class="UnitLibrary_WPF.ConfigureWindowLandscape"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UnitLibrary_WPF"
xmlns:b="clr-namespace:UnitLibrary_WPF.Buttons"
xmlns:u="clr-namespace:UnitLibrary_WPF.UnitImagePanels"
xmlns:s="clr-namespace:UnitLibrary_WPF.Storyboards"
Width="800"
Height="480">
<local:AbstractConfigWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</local:AbstractConfigWindow.Resources>
<Viewbox Margin="10">
<DockPanel x:Name="mainView"
Height="480"
Width="800">
<local:uHeader DockPanel.Dock="Top" />
<local:uBrightnessControl DockPanel.Dock="Top" Height="75" />
<local:uOposButtons Margin="0,5,0,0" DockPanel.Dock="Right" />
<Grid Margin="10">
<Viewbox x:Name="u8800viewbox"
Visibility="Hidden">
<u:u8800Image />
</Viewbox>
<Viewbox x:Name="u9000viewbox"
Visibility="Hidden">
<u:u9000Image />
</Viewbox>
<Viewbox x:Name="u7200viewbox"
Visibility="Hidden">
<u:u7200Image>
<u:u7200Image.LayoutTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform Angle="90" />
<TranslateTransform />
</TransformGroup>
</u:u7200Image.LayoutTransform>
</u:u7200Image>
</Viewbox>
</Grid>
</DockPanel>
</Viewbox>
</local:AbstractConfigWindow>
in the other window I do not rotate u7200Image (that is one of the 3 UserControls that I mentioned earlier).
So the question is how can I add those 3+ controls to the base class so I only have to add them to the base class and not each child class?