Skip to content

Commit a54d678

Browse files
authored
IComponentConnector2 doesn't exist in WinUI (#1156)
* IComponentConnector2 doesn't exist in WinUI * added new header
1 parent dcea885 commit a54d678

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

cppwinrt/code_writers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,11 +3272,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
32723272
}
32733273
else if (namespace_name == "Windows.UI.Xaml.Markup")
32743274
{
3275-
w.write(strings::base_xaml_component_connector, "Windows");
3275+
w.write(strings::base_xaml_component_connector);
32763276
}
32773277
else if (namespace_name == "Microsoft.UI.Xaml.Markup")
32783278
{
3279-
w.write(strings::base_xaml_component_connector, "Microsoft");
3279+
w.write(strings::base_xaml_component_connector_winui);
32803280
}
32813281
}
32823282

cppwinrt/cppwinrt.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<ClInclude Include="..\strings\base_weak_ref.h" />
9090
<ClInclude Include="..\strings\base_windows.h" />
9191
<ClInclude Include="..\strings\base_xaml_component_connector.h" />
92+
<ClInclude Include="..\strings\base_xaml_component_connector_winui.h" />
9293
<ClInclude Include="..\strings\base_xaml_typename.h" />
9394
<ClInclude Include="cmd_reader.h" />
9495
<ClInclude Include="code_writers.h" />

cppwinrt/cppwinrt.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
<ClInclude Include="..\strings\base_coroutine_system_winui.h">
179179
<Filter>strings</Filter>
180180
</ClInclude>
181+
<ClInclude Include="..\strings\base_xaml_component_connector_winui.h">
182+
<Filter>strings</Filter>
183+
</ClInclude>
181184
</ItemGroup>
182185
<ItemGroup>
183186
<ResourceCompile Include="$(OutDir)version.rc" />

strings/base_xaml_component_connector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
WINRT_EXPORT namespace winrt::%::UI::Xaml::Markup
2+
WINRT_EXPORT namespace winrt::Windows::UI::Xaml::Markup
33
{
44
template <typename D>
55
struct ComponentConnectorT : D
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
WINRT_EXPORT namespace winrt::Microsoft::UI::Xaml::Markup
3+
{
4+
template <typename D>
5+
struct ComponentConnectorT : D
6+
{
7+
using composable_base = typename D::composable_base;
8+
9+
void InitializeComponent()
10+
{
11+
if constexpr (m_has_connectable_base)
12+
{
13+
m_dispatch_base = true;
14+
composable_base::InitializeComponent();
15+
m_dispatch_base = false;
16+
}
17+
D::InitializeComponent();
18+
}
19+
20+
void Connect(int32_t connectionId, Windows::Foundation::IInspectable const& target)
21+
{
22+
if constexpr (m_has_connectable_base)
23+
{
24+
if (m_dispatch_base)
25+
{
26+
composable_base::Connect(connectionId, target);
27+
return;
28+
}
29+
}
30+
D::Connect(connectionId, target);
31+
}
32+
33+
auto GetBindingConnector(int32_t connectionId, Windows::Foundation::IInspectable const& target)
34+
{
35+
if constexpr (m_has_connectable_base)
36+
{
37+
if (m_dispatch_base)
38+
{
39+
return composable_base::GetBindingConnector(connectionId, target);
40+
}
41+
}
42+
return D::GetBindingConnector(connectionId, target);
43+
}
44+
45+
private:
46+
static constexpr bool m_has_connectable_base{
47+
impl::has_initializer<composable_base>::value &&
48+
impl::has_interface<D, IComponentConnector>() };
49+
50+
bool m_dispatch_base{};
51+
};
52+
}

0 commit comments

Comments
 (0)