✅ Need help making classes

My current classes don't work, compilation error CS0115 for no reason, i'm crying here.
namespace BeatBooth.Classes.Pages
{
public abstract class EnginePage : Page
{
public abstract void open();
public abstract void close();
public static EnginePage currentPage { get; private set; }

public static void SwitchPage<T>() where T : EnginePage, new()
{
if (currentPage != null)
{
currentPage.close();
}

var newPage = new T();
currentPage = newPage;

GameWindow.Viewport.Content = newPage;
newPage.open();
}
}
}
namespace BeatBooth.Classes.Pages
{
public abstract class EnginePage : Page
{
public abstract void open();
public abstract void close();
public static EnginePage currentPage { get; private set; }

public static void SwitchPage<T>() where T : EnginePage, new()
{
if (currentPage != null)
{
currentPage.close();
}

var newPage = new T();
currentPage = newPage;

GameWindow.Viewport.Content = newPage;
newPage.open();
}
}
}
namespace BeatBooth.Classes.Pages
{
public partial class GameMainMenu : EnginePage
{
public GameMainMenu()
{
InitializeComponent();
}

public override void open()
{
Console.WriteLine("Open");
}

public override void close()
{
Console.WriteLine("Close");
}
}
}
namespace BeatBooth.Classes.Pages
{
public partial class GameMainMenu : EnginePage
{
public GameMainMenu()
{
InitializeComponent();
}

public override void open()
{
Console.WriteLine("Open");
}

public override void close()
{
Console.WriteLine("Close");
}
}
}
24 Replies
Broken Toaster
Broken ToasterOP7mo ago
oh and code CS0263
Pobiega
Pobiega7mo ago
Most people dont memorize the error codes, and even if we look them up they dont contain type names and other details that might be valuable. Can you screenshot or copy the error log?
SleepWellPupper
SleepWellPupper7mo ago
Are you using WPF?
Broken Toaster
Broken ToasterOP7mo ago
yes My log is in czech but it says: partial class GameMainMenu can't define different basic classes couldn't find fittable method to override [ open(); close() ]
Broken Toaster
Broken ToasterOP7mo ago
The namespace copys the file structure
No description
Broken Toaster
Broken ToasterOP7mo ago
Making EnginePage an interface doesn't work... idk what else to do.
The Fog from Human Resources
Show error.
Broken Toaster
Broken ToasterOP7mo ago
. I feel like i might be doing this all wrong or idk
The Fog from Human Resources
I mean the compilation error
SleepWellPupper
SleepWellPupper7mo ago
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/xaml/?view=netdesktop-8.0#events-and-xaml-code-behind You are using a different base class from the c# class that WPF generates for your xaml definition
XAML overview - WPF .NET
Learn how the XAML language is structured and implemented by Windows Presentation Foundation (WPF) for .NET.
SleepWellPupper
SleepWellPupper7mo ago
Since WPF generates a partial MainMenuPage you get the conflicting partial declarations with different base classes Subsequently the compiler is confused and does not recognize your override methods anymore, since it's trying to resolve them via the base class defined in the WPF-generated partial MainMenuPage
SleepWellPupper
SleepWellPupper7mo ago
Stack Overflow
How do you specify a different base class in .xaml files (Silverlig...
How can you specify a common base class in .xaml files for seperate Silverlight Page classes? I have a few common properties that I would like to share across pages, but I don't know how to do this
SleepWellPupper
SleepWellPupper7mo ago
This might help you define the base class in XAML and avoid the partial class conflicts
Broken Toaster
Broken ToasterOP7mo ago
To explain what i'm tryna do - I have a window in which i'll have a game. In this window theres a <Frame/> and i want my own Page class, lets say EnginePage, that inherits from Page cuz it's it's extention. From EnginePage all the other pages inherit. There won't be a EnginePage object, so it's abstract. I want to control the change of pages more "strongly", so a static SwitchPage<T>() function is implemented. I want to allow the pages to have functions that activate when opened and closed, so public abstract void Open() and Close() oh my god
SleepWellPupper
SleepWellPupper7mo ago
Can you share the xaml of your MainMenuPage?
Broken Toaster
Broken ToasterOP7mo ago
I've tried so many things from now, i believe... yup, i deleted the files to start fresh cuz the code is already scatered acros multiple discord convos and ChatGPT chats... here, top message but i'll propably just do a custom XML element with UserControl
SleepWellPupper
SleepWellPupper7mo ago
I meant the actual GameMainMenu.xaml file
Broken Toaster
Broken ToasterOP7mo ago
oh... i mean i didn't change anything... except namespaces and class name when renaming stuff but i checked multiple times that it was correct.
SleepWellPupper
SleepWellPupper7mo ago
If you share your xaml code I can help you figure out how to change it to define the base class used in the WPF-generated c# code
Broken Toaster
Broken ToasterOP7mo ago
ok
namespace BeatBooth.pages
{
/// <summary>
/// Interakční logika pro EnginePage.xaml
/// </summary>
public class EnginePage : UserControl
{
int number = 8;
}
}
namespace BeatBooth.pages
{
/// <summary>
/// Interakční logika pro EnginePage.xaml
/// </summary>
public class EnginePage : UserControl
{
int number = 8;
}
}
<local:EnginePage
x:Class="BeatBooth.pages.GameMainMenu"
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:BeatBooth.pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"/>
<local:EnginePage
x:Class="BeatBooth.pages.GameMainMenu"
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:BeatBooth.pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"/>
namespace BeatBooth.pages
{
/// <summary>
/// Interakční logika pro GameMainMenu.xaml
/// </summary>
public partial class GameMainMenu : EnginePage
{
public GameMainMenu()
{
InitializeComponent();
}
}
}
namespace BeatBooth.pages
{
/// <summary>
/// Interakční logika pro GameMainMenu.xaml
/// </summary>
public partial class GameMainMenu : EnginePage
{
public GameMainMenu()
{
InitializeComponent();
}
}
}
ERROR: Name EnginePage doesn't exist in clr-namespace:BeatBooth.pages - XDG0008 EnginePage doesn't have xml, i assumed from the StackOverflow that it didn't need one.
SleepWellPupper
SleepWellPupper7mo ago
I'm assuming the xaml code is from the GameMainMenu.xaml file? If so, change xmlns:local="clr-namespace:BeatBooth.pages" xmlns:local="clr-namespace:BeatBooth.Classes.Pages" Otherwise, it's attempting to localize your EnginePage class in the BeatBooth.pages namespace where of course it doesn't exist.
Broken Toaster
Broken ToasterOP7mo ago
I figured it all out Thx for the help
SleepWellPupper
SleepWellPupper7mo ago
$close
MODiX
MODiX7mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server