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
4
  • 1
    Can you show the definition of the namespace base in your xaml file? Commented Sep 9, 2020 at 9:57
  • Just a simple thing to try - clean & rebuild. Sometimes WPF gets screwed up and this will fix certain errors. Probably not the problem but easy to try... Commented Sep 9, 2020 at 14:41
  • Also - you should double check that ProjectSABX.Pages is the correct namespace for class Home Commented Sep 9, 2020 at 14:43
  • Also, did you see stackoverflow.com/questions/8800872/… ? Commented Sep 9, 2020 at 14:43

1 Answer 1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.