What properties/functions/anything must go in the IDLs that I write for custom XAML controls written in C++/WinRT?
Example
When I create a custom C++/WinRT XAML control in Visual Studio, it creates 4 files:
- MyControl.xaml
- MyControl.idl
- MyControl.h
- MyControl.cpp
The IDL file is basic and includes a simple property:
namespace MyNamespace
{
[default_interface]
runtimeclass MyControl : Windows.UI.Xaml.Controls.UserControl
{
MyControl();
Int32 MyProperty;
}
}
Interestingly, the .h file also includes another function in addition to this property:
#pragma once
#include "winrt/Windows.UI.Xaml.h"
#include "winrt/Windows.UI.Xaml.Markup.h"
#include "winrt/Windows.UI.Xaml.Interop.h"
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
#include "MyControl.g.h"
namespace winrt::MyNamespace::implementation
{
struct MyControl : MyControlT<MyControl>
{
MyControl();
int32_t MyProperty();
void MyProperty(int32_t value);
void ClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
};
}
namespace winrt::MyNamespace::factory_implementation
{
struct MyControl : MyControlT<MyControl, implementation::MyControl>
{
};
}
Which the .xaml has no problem binding to:
<!-- ... -->
<Button x:Name="Button" Click="ClickHandler">Click Me</Button>
<!-- ... -->
Question
It's not clear to me when I need to introduce a function or property on my IDL in order to consume it in XAML.
Do all properties need to be added to the IDL? Just dependency properties? Do functions ever have to appear in the IDL?
Why does MyProperty appear in the IDL, but not ClickHandler?
Thanks!