dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
602 stars 38 forks source link

Extend documentation on how to change window base class in XAML #19

Closed chausner closed 2 years ago

chausner commented 2 years ago

I got the following error after changing the base class to WindowEx in the code-behind:

error CS0263: Partial declarations of 'MainWindow' must not specify different base classes

Took me a few minutes to figure out that I would need to change the tag name in XAML, as well:

<winuiex:WindowEx
    xmlns:winuiex="using:WinUIEx">
</winuiex:WindowEx>

I suggest to extend the documentation by mentioning this fact and ideally including some sample code to make this clearer to users.

TRadigk commented 2 years ago

@chausner are you able to elaborate further? I am trying to adapt my code from Window to WindowEx, but I am failing miserably. I can do this:

<Window
    x:Class="Ennex.MainWindow:WindowEx"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Ennex"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:views="using:Ennex.Views"
    mc:Ignorable="d">

which solves the errors in c# code of MainWindow.xaml.cs, but then I get errors everywhere on "InitializeComponent". Using Windows App SDK 1.0.0 Release

chausner commented 2 years ago

@TRadigk This should work:

<winuiex:WindowEx
    x:Class="Ennex.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Ennex"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:views="using:Ennex.Views"
    xmlns:winuiex="using:WinUIEx"
    mc:Ignorable="d">
...
</winuiex:WindowEx>
TRadigk commented 2 years ago

It feels like a thumbs up is not enough: @chausner thank you!

dotMorten commented 2 years ago

Better? https://dotmorten.github.io/WinUIEx/concepts/WindowEx.html#usage