2

I want to build my own set of objects to be used as a base line for a project. I created my Main window and pages that navigate through. However I couldn't find a way to implement a base class where I'll set all the objects that I will use in multiple pages such as the filePath.

here's an example on what I tried to do:

.XAML:

<base: PageBase x:Class="ProjectSABX.Pages.Home"
  <PageBase.Resources>
   ...
  </PageBase.Resources>
  <Grid>
   ...
  </Grid>
</base: PageBase>

.CS:

Home.cs:

namespace ProjectSABX
{
  public partial class Home : PageBase
    {
       Public Home ()
         {
           InitializeComponent();
         }
    }
}

PageBase.cs:

namespace ProjectSABX
{
  public class PageBase : Page
    {
      public string filePath;
        ...
    }
}

When I do so I get this error message:

Partial declarations of 'Home' must not specify different base classes
Neuron
  • 5,141
  • 5
  • 38
  • 59

1 Answers1

1

Should work if you just map base to the CLR namespace of the PageBase class:

HomePage.xaml:

<local:PageBase x:Class="WpfApp1.HomePage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:WpfApp1"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="Page1">
    <Grid>
        <TextBlock>The page...</TextBlock>
    </Grid>
</local:PageBase>

HomePage.xaml.cs:

namespace WpfApp1
{
    public partial class HomePage : PageBase
    {
        public HomePage()
        {
            InitializeComponent();
        }
    }
}

PageBase.cs:

namespace WpfApp1
{
    public class PageBase : Page
    {
        public string filePath;
    }
}
mm8
  • 163,881
  • 10
  • 57
  • 88