I have usercontrols which inherit a base class which looks like this:
BasePage.cs:
using System.Windows.Controls;
namespace TestPageManager23434
{
public class BasePage : UserControl
{
public string ButtonPreviousText { get; set; }
public string ButtonNextText { get; set; }
protected PageManager pageManager;
public BasePage(PageManager pageManager)
{
this.pageManager = pageManager;
}
}
}
And the user controls which look like this:
XAML:
<local:BasePage x:Class="TestPageManager23434.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:TestPageManager23434"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Background="White"
Width="400"
Height="400"
>
<TextBlock Text="this is page1"/>
<TextBlock Text="{Binding Message}"/>
<Button Content="go to page 2" Click="Button_Click"
HorizontalAlignment="Left"
Width="200"
Height="30"
/>
</StackPanel>
</local:BasePage>
Code Behind:
using System.Windows.Controls;
namespace TestPageManager23434
{
public partial class Page1 : BasePage
{
public string Message { get; set; }
public Page1(PageManager pageManager) : base(pageManager)
{
InitializeComponent();
DataContext = this;
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
pageManager.SwitchPage("page2");
}
}
}
But now in my XAML portions of my various UserControls I also have XAML blocks which I would also like to inherit from the base class so that I don't have this block copied in each XAML file:
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
<Button
Content="{Binding ButtonPreviousText}"
Width="150"
Margin="5"
Click="ButtonPrevious_Click"/>
<Button
Content="{Binding ButtonNextText}"
Width="150"
Click="ButtonNext_Click" Margin="5"/>
</StackPanel>
But since my base class has no XAML, I see two ways:
- create them in code in my base class
- create usercontrols for them
Or is there another way to have this XAML in one location or some way to inherit XAML?