Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
Generated Files/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.idl": "cpp"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ using namespace Windows::UI::Xaml::Controls;
using namespace Microsoft::Xaml::Interactions::Core;
using namespace Windows::UI::Xaml::Controls::Primitives;

struct CompareString
struct CompareStringX
{
bool operator() (const wchar_t* lhs, const wchar_t* rhs) const
{
return wcscmp(lhs, rhs) < 0;
}
};

typedef std::map<const wchar_t*, RegisterHandler, CompareString> EventNameToRegisterHandlerMap;
typedef std::map<const wchar_t*, UnregisterHandler, CompareString> EventNameToUnregisterHandlerMap;
typedef std::map<const wchar_t*, RegisterHandler, CompareStringX> EventNameToRegisterHandlerMap;
typedef std::map<const wchar_t*, UnregisterHandler, CompareStringX> EventNameToUnregisterHandlerMap;

namespace Global
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.10240.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
Expand All @@ -51,35 +51,35 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "pch.h"
#include "ActionCollection.h"
#include "IAction.h"
#include "ResourceHelper.h"

using namespace Platform;
using namespace Windows::UI::Xaml;
namespace winrt
{
using namespace Windows::Foundation::Collections;
using namespace Microsoft::Xaml::Interactivity;
using namespace Windows::UI::Xaml;
} // namespace winrt

namespace winrt::Microsoft::Xaml::Interactivity::implementation
{
ActionCollection::ActionCollection()
{
this->VectorChanged += ref new VectorChangedEventHandler<DependencyObject^>(this, &ActionCollection::OnVectorChanged);
_vectorChanged = VectorChanged(auto_revoke, {get_weak(), &ActionCollection::OnVectorChanged});
}

void ActionCollection::OnVectorChanged(IObservableVector<DependencyObject^>^ sender, IVectorChangedEventArgs^ eventArgs)
void ActionCollection::OnVectorChanged(IObservableVector<DependencyObject> const &, IVectorChangedEventArgs const &event)
{
CollectionChange collectionChange = eventArgs->CollectionChange;
auto collectionChange = event.CollectionChange();

if (collectionChange == CollectionChange::Reset)
{
for (const auto& item : this)
{
ActionCollection::VerifyType(item);
}
}
else if (collectionChange == CollectionChange::ItemInserted || collectionChange == CollectionChange::ItemChanged)
{
auto changedItem = this->GetAt(eventArgs->Index);
ActionCollection::VerifyType(changedItem);
}
if (collectionChange == CollectionChange::Reset)
{
for (auto const &item : *this)
{
ActionCollection::VerifyType(item);
}
}
else if (collectionChange == CollectionChange::ItemInserted || collectionChange == CollectionChange::ItemChanged)
{
auto changedItem = GetAt(event.Index());
ActionCollection::VerifyType(changedItem);
}
}

void ActionCollection::VerifyType(DependencyObject^ item)
void ActionCollection::VerifyType(DependencyObject const &item)
{
IAction^ action = dynamic_cast<IAction^>(item);

if (action == nullptr)
{
throw ref new FailureException(ResourceHelper::GetString("NonActionAddedToActionCollectionExceptionMessage"));
}
}
auto type = item.try_as<IAction>();
if (type == nullptr)
{
// ResourceHelper::GetString("NonActionAddedToActionCollectionExceptionMessage")
throw winrt::hresult_invalid_argument(L"NonActionAddedToActionCollectionExceptionMessage");
}
}
} // namespace winrt::Microsoft::Xaml::Interactivity::implementation
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma once
#include "ActionCollection.g.h"

namespace Microsoft { namespace Xaml { namespace Interactivity
namespace winrt::Microsoft::Xaml::Interactivity::implementation
{
/// <summary>
/// Represents a collection of IActions.
/// </summary>
public ref class ActionCollection sealed : ::Windows::UI::Xaml::DependencyObjectCollection
{
public:
/// <summary>
/// Initializes a new instance of the <see cref="ActionCollection"/> class.
/// </summary>
ActionCollection();
/// <summary>
/// Represents a collection of IActions.
/// </summary>
struct ActionCollection : ActionCollectionT<ActionCollection>
{
/// <summary>
/// Initializes a new instance of the <see cref="ActionCollection"/> class.
/// </summary>
ActionCollection();

private:
void OnVectorChanged(
::Windows::Foundation::Collections::IObservableVector<::Windows::UI::Xaml::DependencyObject^>^ sender,
::Windows::Foundation::Collections::IVectorChangedEventArgs^ eventArgs);
private:
VectorChanged_revoker _vectorChanged;

static void VerifyType(::Windows::UI::Xaml::DependencyObject^ item);
};
void OnVectorChanged(
Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::DependencyObject> const &sender,
Windows::Foundation::Collections::IVectorChangedEventArgs const &event);

}}}
static void VerifyType(Windows::UI::Xaml::DependencyObject const &item);
};
} // namespace winrt::Microsoft::Xaml::Interactivity::implementation
namespace winrt::Microsoft::Xaml::Interactivity::factory_implementation
{
struct ActionCollection : ActionCollectionT<ActionCollection, implementation::ActionCollection>
{
};
} // namespace winrt::Microsoft::Xaml::Interactivity::factory_implementation
Loading