I have created a minimalist WinUI(3) WinRT/C++ Desktop (Blank, Packaged) and added a single UserControl. The module that is added compiles and runs just fine. But I want to deal with DependencyProperties so I'm trying to build up to that in small increments. My .idl file shows the runtimeclass inherits from winrt::Microsoft.UI.Xaml.Controls.UserControl but the .h file lacks the same inheritance in the struct definition. I can't figure out why I can't add the inheritance to the CalcButtonT in the implementation. When I do I get the error message that says:
static_assert failed: 'Class must derive from implements<> or ClassT<> where the first template parameter is the derived class name, e.g. struct D : implements<D, ...>'
What the error message fails to show is which class it is referring to. The build messages lead me to believe it is my CalcButton class. Also, when I have tried to add DependencyProperties to my CalcButton, I get a message that one of the steps in a OneWay mode must implement INotifyPropertyChange. But if I add the Microsoft::UI::Xaml::Data::INotifyPropertyChange to the inheritance, I get a message that it is already a base inheritance class.
Here are my four files. The remaining code within this project has been left untouched from the creation of my blank project. I am not trying to use my CalcButton, just get it up and building.
CalcButton.idl:
namespace ThirdCppAppv3
{
[default_interface]
runtimeclass CalcButton : Microsoft.UI.Xaml.Controls.UserControl
{
CalcButton();
}
}
CalcButton.xaml:
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="ThirdCppAppv3.CalcButton"
xmlns=";
xmlns:x=";
xmlns:local="using:ThirdCppAppv3"
xmlns:d=";
xmlns:mc=";
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click" Content="Custom Button"></Button>
</StackPanel>
</UserControl>
CalcButton.xaml.h:
#pragma once
#include "CalcButton.g.h"
namespace winrt::ThirdCppAppv3::implementation
{
struct CalcButton : CalcButtonT<CalcButton, Microsoft::UI::Xaml::Controls::UserControl>
{
CalcButton();
void myButton_Click(IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&);
};
}
namespace winrt::ThirdCppAppv3::factory_implementation
{
struct CalcButton : CalcButtonT<CalcButton, implementation::CalcButton>
{
};
}
CalcButton.xaml.cpp:
#include "pch.h"
#include "CalcButton.xaml.h"
#include "CalcButton.g.cpp"
using namespace winrt;
using namespace Microsoft::UI::Xaml;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: .
namespace winrt::ThirdCppAppv3::implementation
{
CalcButton::CalcButton()
{
}
void CalcButton::myButton_Click(IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
{
}
}
It's got to be something stupid I can't see. It's also frustrating that I can't find any recent samples of UserControls
Peter