├── .gitattributes ├── .gitignore ├── App.cpp ├── App.h ├── App.idl ├── App.xaml ├── Assets ├── LockScreenLogo.scale-200.png ├── SplashScreen.scale-200.png ├── Square150x150Logo.scale-200.png ├── Square44x44Logo.scale-200.png ├── Square44x44Logo.targetsize-24_altform-unplated.png ├── StoreLogo.png └── Wide310x150Logo.scale-200.png ├── Controls ├── SimpleUserControl.cpp ├── SimpleUserControl.h ├── SimpleUserControl.idl └── SimpleUserControl.xaml ├── Framework ├── BindableBase.cpp ├── BindableBase.h ├── BindableBase.idl ├── DelegateCommand.cpp ├── DelegateCommand.h ├── DelegateCommand.idl ├── ScaleConverter.cpp ├── ScaleConverter.h └── ScaleConverter.idl ├── MvvmCppWinRT.sln ├── MvvmCppWinRT.vcxproj ├── MvvmCppWinRT.vcxproj.filters ├── Package.appxmanifest ├── Pages ├── MainPage.cpp ├── MainPage.h ├── MainPage.idl └── MainPage.xaml ├── PropertySheet.props ├── ViewModels ├── MainViewModel.cpp ├── MainViewModel.h └── MainViewModel.idl ├── packages.config ├── pch.cpp ├── pch.h └── readme.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | 263 | /Generated Files/ -------------------------------------------------------------------------------- /App.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // App.xaml.cpp 3 | // Implementation of the App class. 4 | // 5 | 6 | #include "pch.h" 7 | 8 | #include "App.h" 9 | #include "Pages/MainPage.h" 10 | 11 | using namespace winrt; 12 | using namespace Windows::ApplicationModel; 13 | using namespace Windows::ApplicationModel::Activation; 14 | using namespace Windows::Foundation; 15 | using namespace Windows::UI::Xaml; 16 | using namespace Windows::UI::Xaml::Controls; 17 | using namespace Windows::UI::Xaml::Navigation; 18 | using namespace MvvmCppWinRT; 19 | using namespace MvvmCppWinRT::implementation; 20 | 21 | /// 22 | /// Initializes the singleton application object. This is the first line of authored code 23 | /// executed, and as such is the logical equivalent of main() or WinMain(). 24 | /// 25 | App::App() 26 | { 27 | InitializeComponent(); 28 | Suspending({ this, &App::OnSuspending }); 29 | 30 | #if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION 31 | UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) 32 | { 33 | if (IsDebuggerPresent()) 34 | { 35 | auto errorMessage = e.Message(); 36 | __debugbreak(); 37 | } 38 | }); 39 | #endif 40 | } 41 | 42 | /// 43 | /// Invoked when the application is launched normally by the end user. Other entry points 44 | /// will be used such as when the application is launched to open a specific file. 45 | /// 46 | /// Details about the launch request and process. 47 | void App::OnLaunched(LaunchActivatedEventArgs const& e) 48 | { 49 | Frame rootFrame{ nullptr }; 50 | auto content = Window::Current().Content(); 51 | if (content) 52 | { 53 | rootFrame = content.try_as(); 54 | } 55 | 56 | // Do not repeat app initialization when the Window already has content, 57 | // just ensure that the window is active 58 | if (rootFrame == nullptr) 59 | { 60 | // Create a Frame to act as the navigation context and associate it with 61 | // a SuspensionManager key 62 | rootFrame = Frame(); 63 | 64 | rootFrame.NavigationFailed({ this, &App::OnNavigationFailed }); 65 | 66 | if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated) 67 | { 68 | // Restore the saved session state only when appropriate, scheduling the 69 | // final launch steps after the restore is complete 70 | } 71 | 72 | if (e.PrelaunchActivated() == false) 73 | { 74 | if (rootFrame.Content() == nullptr) 75 | { 76 | // When the navigation stack isn't restored navigate to the first page, 77 | // configuring the new page by passing required information as a navigation 78 | // parameter 79 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments())); 80 | } 81 | // Place the frame in the current Window 82 | Window::Current().Content(rootFrame); 83 | // Ensure the current window is active 84 | Window::Current().Activate(); 85 | } 86 | } 87 | else 88 | { 89 | if (e.PrelaunchActivated() == false) 90 | { 91 | if (rootFrame.Content() == nullptr) 92 | { 93 | // When the navigation stack isn't restored navigate to the first page, 94 | // configuring the new page by passing required information as a navigation 95 | // parameter 96 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments())); 97 | } 98 | // Ensure the current window is active 99 | Window::Current().Activate(); 100 | } 101 | } 102 | } 103 | 104 | /// 105 | /// Invoked when application execution is being suspended. Application state is saved 106 | /// without knowing whether the application will be terminated or resumed with the contents 107 | /// of memory still intact. 108 | /// 109 | /// The source of the suspend request. 110 | /// Details about the suspend request. 111 | void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e) 112 | { 113 | // Save application state and stop any background activity 114 | } 115 | 116 | /// 117 | /// Invoked when Navigation to a certain page fails 118 | /// 119 | /// The Frame which failed navigation 120 | /// Details about the navigation failure 121 | void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e) 122 | { 123 | throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name); 124 | } -------------------------------------------------------------------------------- /App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "App.xaml.g.h" 3 | 4 | namespace winrt::MvvmCppWinRT::implementation 5 | { 6 | struct App : AppT 7 | { 8 | App(); 9 | 10 | void OnLaunched(winrt::Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&); 11 | void OnSuspending(winrt::Windows::Foundation::IInspectable const&, winrt::Windows::ApplicationModel::SuspendingEventArgs const&); 12 | void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const&, winrt::Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&); 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /App.idl: -------------------------------------------------------------------------------- 1 | namespace MvvmCppWinRT 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | -------------------------------------------------------------------------------- /Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/StoreLogo.png -------------------------------------------------------------------------------- /Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johanlindfors/MvvmCppWinRT/6097adf4ec5e8a4a5a33f85b0da19a01f7283e3b/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /Controls/SimpleUserControl.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "SimpleUserControl.h" 3 | #if __has_include("SimpleUserControl.g.cpp") 4 | #include "SimpleUserControl.g.cpp" 5 | #endif 6 | 7 | using namespace winrt; 8 | using namespace Windows::UI::Xaml; 9 | 10 | namespace winrt::MvvmCppWinRT::implementation 11 | { 12 | SimpleUserControl::SimpleUserControl() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | int32_t SimpleUserControl::MyProperty() 18 | { 19 | throw hresult_not_implemented(); 20 | } 21 | 22 | void SimpleUserControl::MyProperty(int32_t /* value */) 23 | { 24 | throw hresult_not_implemented(); 25 | } 26 | 27 | void SimpleUserControl::ClickHandler(IInspectable const&, RoutedEventArgs const&) 28 | { 29 | Button().Content(box_value(L"Clicked")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Controls/SimpleUserControl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "winrt/Windows.UI.Xaml.h" 4 | #include "winrt/Windows.UI.Xaml.Markup.h" 5 | #include "winrt/Windows.UI.Xaml.Interop.h" 6 | #include "winrt/Windows.UI.Xaml.Controls.Primitives.h" 7 | #include "SimpleUserControl.g.h" 8 | 9 | namespace winrt::MvvmCppWinRT::implementation 10 | { 11 | struct SimpleUserControl : SimpleUserControlT 12 | { 13 | SimpleUserControl(); 14 | 15 | int32_t MyProperty(); 16 | void MyProperty(int32_t value); 17 | 18 | void ClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); 19 | }; 20 | } 21 | 22 | namespace winrt::MvvmCppWinRT::factory_implementation 23 | { 24 | struct SimpleUserControl : SimpleUserControlT 25 | { 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /Controls/SimpleUserControl.idl: -------------------------------------------------------------------------------- 1 | namespace MvvmCppWinRT 2 | { 3 | [default_interface] 4 | runtimeclass SimpleUserControl : Windows.UI.Xaml.Controls.UserControl 5 | { 6 | SimpleUserControl(); 7 | Int32 MyProperty; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Controls/SimpleUserControl.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Framework/BindableBase.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "BindableBase.h" 3 | #include "BindableBase.g.cpp" 4 | 5 | using namespace winrt; 6 | using namespace Windows::UI::Xaml::Data; 7 | 8 | namespace winrt::MvvmCppWinRT::implementation 9 | { 10 | void BindableBase::RaisePropertyChanged(hstring const& propertyName) 11 | { 12 | propertyChanged(*this, PropertyChangedEventArgs(propertyName)); 13 | } 14 | 15 | event_token BindableBase::PropertyChanged(PropertyChangedEventHandler const& handler) 16 | { 17 | return propertyChanged.add(handler); 18 | } 19 | 20 | void BindableBase::PropertyChanged(winrt::event_token const& token) noexcept 21 | { 22 | propertyChanged.remove(token); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Framework/BindableBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BindableBase.g.h" 3 | 4 | namespace winrt::MvvmCppWinRT::implementation 5 | { 6 | struct BindableBase : BindableBaseT 7 | { 8 | void RaisePropertyChanged(winrt::hstring const& propertyName); 9 | winrt::event_token PropertyChanged(winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler); 10 | void PropertyChanged(winrt::event_token const& token) noexcept; 11 | 12 | private: 13 | event propertyChanged; 14 | }; 15 | } 16 | 17 | namespace winrt::MvvmCppWinRT::factory_implementation 18 | { 19 | struct BindableBase : BindableBaseT 20 | { 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /Framework/BindableBase.idl: -------------------------------------------------------------------------------- 1 | namespace MvvmCppWinRT 2 | { 3 | [default_interface] 4 | unsealed runtimeclass BindableBase : Windows.UI.Xaml.DependencyObject, Windows.UI.Xaml.Data.INotifyPropertyChanged 5 | { 6 | BindableBase(); 7 | protected void RaisePropertyChanged(String propertyName); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Framework/DelegateCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DelegateCommand.h" 3 | 4 | using namespace std; 5 | using namespace winrt; 6 | using namespace Windows::Foundation; 7 | 8 | namespace winrt::MvvmCppWinRT::implementation 9 | { 10 | DelegateCommand::DelegateCommand(function const& execute) 11 | : DelegateCommand(execute, nullptr) 12 | {} 13 | 14 | DelegateCommand::DelegateCommand(function const& execute, function const& canExecute) 15 | { 16 | if (execute == nullptr) { 17 | throw hresult_invalid_argument(L"execute"); 18 | } 19 | executeDelegate = execute; 20 | canExecuteDelegate = canExecute; 21 | } 22 | 23 | void DelegateCommand::RaiseCanExecuteChanged() 24 | { 25 | canExecuteChanged(*this, IInspectable()); 26 | } 27 | 28 | event_token DelegateCommand::CanExecuteChanged(EventHandler const& handler) 29 | { 30 | return canExecuteChanged.add(handler); 31 | } 32 | 33 | void DelegateCommand::CanExecuteChanged(event_token const& token) 34 | { 35 | canExecuteChanged.remove(token); 36 | } 37 | 38 | bool DelegateCommand::CanExecute(IInspectable const& parameter) 39 | { 40 | if (canExecuteDelegate == nullptr) { 41 | return true; 42 | } 43 | 44 | bool canExecute = canExecuteDelegate(parameter); 45 | 46 | if (lastCanExecute != canExecute) { 47 | lastCanExecute = canExecute; 48 | RaiseCanExecuteChanged(); 49 | } 50 | 51 | return lastCanExecute; 52 | } 53 | 54 | void DelegateCommand::Execute(IInspectable const& parameter) 55 | { 56 | if (executeDelegate != nullptr) { 57 | executeDelegate(parameter); 58 | } 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /Framework/DelegateCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DelegateCommand.g.h" 4 | #include 5 | 6 | namespace winrt::MvvmCppWinRT::implementation 7 | { 8 | struct DelegateCommand : DelegateCommandT 9 | { 10 | DelegateCommand(std::function const& execute); 11 | 12 | DelegateCommand(std::function const& execute, std::function const& canExecute); 13 | 14 | void RaiseCanExecuteChanged(); 15 | 16 | winrt::event_token CanExecuteChanged(winrt::Windows::Foundation::EventHandler const& handler); 17 | 18 | void CanExecuteChanged(winrt::event_token const& token); 19 | 20 | bool CanExecute(winrt::Windows::Foundation::IInspectable const& parameter); 21 | 22 | void Execute(winrt::Windows::Foundation::IInspectable const& parameter); 23 | 24 | private: 25 | event> canExecuteChanged; 26 | 27 | std::function executeDelegate; 28 | std::function canExecuteDelegate; 29 | bool lastCanExecute = true; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /Framework/DelegateCommand.idl: -------------------------------------------------------------------------------- 1 | namespace MvvmCppWinRT 2 | { 3 | runtimeclass DelegateCommand : Windows.UI.Xaml.DependencyObject, Windows.UI.Xaml.Input.ICommand 4 | { 5 | void RaiseCanExecuteChanged(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Framework/ScaleConverter.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pch.h" 3 | #include "ScaleConverter.h" 4 | #include "ScaleConverter.g.cpp" 5 | 6 | using namespace std; 7 | using namespace winrt; 8 | using namespace Windows::Foundation; 9 | using namespace Windows::UI::Xaml::Interop; 10 | 11 | namespace winrt::MvvmCppWinRT::implementation 12 | { 13 | IInspectable ScaleConverter::Convert( 14 | IInspectable const& value, 15 | TypeName const& targetType, 16 | IInspectable const& parameter, 17 | hstring const& /*language*/) 18 | { 19 | if (targetType.Name != L"Double") 20 | { 21 | throw hresult_invalid_argument(); 22 | } 23 | 24 | double numValue = unbox_value(value); 25 | 26 | hstring paramString = unbox_value(parameter); 27 | 28 | double numParam = stod(wstring(paramString.data())); 29 | if (numParam == 0) { 30 | numParam = 1; 31 | } 32 | 33 | return box_value(numValue * numParam); 34 | } 35 | 36 | IInspectable ScaleConverter::ConvertBack( 37 | IInspectable const& /*value*/, 38 | TypeName const& /*targetType*/, 39 | IInspectable const& /*parameter*/, 40 | hstring const& /*language*/) 41 | { 42 | throw hresult_not_implemented(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Framework/ScaleConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ScaleConverter.g.h" 3 | 4 | namespace winrt::MvvmCppWinRT::implementation 5 | { 6 | struct ScaleConverter : ScaleConverterT 7 | { 8 | ScaleConverter() = default; 9 | 10 | winrt::Windows::Foundation::IInspectable Convert( 11 | winrt::Windows::Foundation::IInspectable const& value, 12 | winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, 13 | winrt::Windows::Foundation::IInspectable const& parameter, 14 | winrt::hstring const& language); 15 | 16 | winrt::Windows::Foundation::IInspectable ConvertBack( 17 | winrt::Windows::Foundation::IInspectable const& value, 18 | winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, 19 | winrt::Windows::Foundation::IInspectable const& parameter, 20 | winrt::hstring const& language); 21 | }; 22 | } 23 | 24 | namespace winrt::MvvmCppWinRT::factory_implementation 25 | { 26 | struct ScaleConverter : ScaleConverterT 27 | { 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /Framework/ScaleConverter.idl: -------------------------------------------------------------------------------- 1 | namespace MvvmCppWinRT 2 | { 3 | [default_interface] 4 | runtimeclass ScaleConverter : Windows.UI.Xaml.DependencyObject, Windows.UI.Xaml.Data.IValueConverter 5 | { 6 | ScaleConverter(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MvvmCppWinRT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MvvmCppWinRT", "MvvmCppWinRT.vcxproj", "{8D0307BA-5EC2-4545-B7ED-664707EC4C41}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|ARM = Release|ARM 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|ARM.ActiveCfg = Debug|ARM 19 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|ARM.Build.0 = Debug|ARM 20 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|ARM.Deploy.0 = Debug|ARM 21 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x64.ActiveCfg = Debug|x64 22 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x64.Build.0 = Debug|x64 23 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x64.Deploy.0 = Debug|x64 24 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x86.ActiveCfg = Debug|Win32 25 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x86.Build.0 = Debug|Win32 26 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Debug|x86.Deploy.0 = Debug|Win32 27 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|ARM.ActiveCfg = Release|ARM 28 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|ARM.Build.0 = Release|ARM 29 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|ARM.Deploy.0 = Release|ARM 30 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x64.ActiveCfg = Release|x64 31 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x64.Build.0 = Release|x64 32 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x64.Deploy.0 = Release|x64 33 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x86.ActiveCfg = Release|Win32 34 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x86.Build.0 = Release|Win32 35 | {8D0307BA-5EC2-4545-B7ED-664707EC4C41}.Release|x86.Deploy.0 = Release|Win32 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {D5D3C20F-8AFE-4928-AA00-899A28E1C30A} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /MvvmCppWinRT.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | true 6 | true 7 | {8d0307ba-5ec2-4545-b7ed-664707ec4c41} 8 | MvvmCppWinRT 9 | MvvmCppWinRT 10 | en-US 11 | 15.0 12 | true 13 | Windows Store 14 | 10.0 15 | 10.0 16 | 10.0.22621.0 17 | 18 | 19 | 20 | 21 | Debug 22 | ARM 23 | 24 | 25 | Debug 26 | Win32 27 | 28 | 29 | Debug 30 | x64 31 | 32 | 33 | Release 34 | ARM 35 | 36 | 37 | Release 38 | Win32 39 | 40 | 41 | Release 42 | x64 43 | 44 | 45 | 46 | Application 47 | v143 48 | v141 49 | v142 50 | Unicode 51 | 52 | 53 | true 54 | true 55 | 56 | 57 | false 58 | true 59 | false 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | MvvmCppWinRT_TemporaryKey.pfx 73 | 1132EA939A7107B303D4D40ED6CE28778FC96409 74 | 75 | 76 | 77 | Use 78 | pch.h 79 | $(IntDir)pch.pch 80 | Level4 81 | /DWINRT_NO_MAKE_DETECTION %(AdditionalOptions) 82 | 4453;28204 83 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 84 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 85 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 86 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 87 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 88 | $(GeneratedFilesDir)Pages;$(GeneratedFilesDir)Framework;$(GeneratedFilesDir)ViewModels;$(GeneratedFilesDir)Controls;%(AdditionalIncludeDirectories) 89 | 90 | 91 | 92 | 93 | Framework\BindableBase.idl 94 | Code 95 | 96 | 97 | Framework\DelegateCommand.idl 98 | Code 99 | 100 | 101 | Framework\ScaleConverter.idl 102 | Code 103 | 104 | 105 | 106 | App.xaml 107 | 108 | 109 | Pages\MainPage.xaml 110 | 111 | 112 | Controls\SimpleUserControl.xaml 113 | Code 114 | 115 | 116 | ViewModels\MainViewModel.idl 117 | Code 118 | 119 | 120 | 121 | 122 | Designer 123 | 124 | 125 | Designer 126 | 127 | 128 | Designer 129 | 130 | 131 | 132 | 133 | Designer 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | Framework\DelegateCommand.idl 150 | Code 151 | 152 | 153 | Framework\BindableBase.idl 154 | Code 155 | 156 | 157 | Framework\ScaleConverter.idl 158 | Code 159 | 160 | 161 | 162 | Create 163 | 164 | 165 | App.xaml 166 | 167 | 168 | Pages\MainPage.xaml 169 | 170 | 171 | Controls\SimpleUserControl.xaml 172 | Code 173 | 174 | 175 | ViewModels\MainViewModel.idl 176 | Code 177 | 178 | 179 | 180 | 181 | App.xaml 182 | 183 | 184 | Designer 185 | 186 | 187 | Designer 188 | 189 | 190 | Designer 191 | 192 | 193 | Pages\MainPage.xaml 194 | 195 | 196 | Controls\SimpleUserControl.xaml 197 | Code 198 | 199 | 200 | Designer 201 | 202 | 203 | 204 | 205 | 206 | false 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /MvvmCppWinRT.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Framework 10 | 11 | 12 | ViewModels 13 | 14 | 15 | 16 | Framework 17 | 18 | 19 | Framework 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Framework 31 | 32 | 33 | Framework 34 | 35 | 36 | Framework 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Assets 53 | 54 | 55 | Assets 56 | 57 | 58 | Assets 59 | 60 | 61 | Assets 62 | 63 | 64 | Assets 65 | 66 | 67 | Assets 68 | 69 | 70 | Assets 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | {e48dc53e-40b1-40cb-970a-f89935452892} 84 | 85 | 86 | {11406d34-6e78-41cc-8d11-234b7c92c42d} 87 | 88 | 89 | {985d5906-a4a5-48ba-8032-cb9fcee01e74} 90 | 91 | 92 | {e53185eb-e6a7-472d-88d7-b693ae3d35d8} 93 | 94 | 95 | {0202f3af-3bbe-41f8-8de7-36f8f720f3c3} 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Pages 104 | 105 | 106 | Controls 107 | 108 | 109 | -------------------------------------------------------------------------------- /Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 7 | 8 | 9 | MvvmCppWinRT 10 | johan 11 | Assets\StoreLogo.png 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Pages/MainPage.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "MainPage.h" 3 | #include "MainPage.g.cpp" 4 | #include "ViewModels/MainViewModel.h" 5 | 6 | using namespace winrt; 7 | using namespace Windows::UI::Xaml; 8 | 9 | namespace winrt::MvvmCppWinRT::implementation 10 | { 11 | MainPage::MainPage() 12 | { 13 | viewModel = make(); 14 | viewModel.Title(L"Click me"); 15 | 16 | InitializeComponent(); 17 | 18 | DataContext(ViewModel()); 19 | } 20 | 21 | MvvmCppWinRT::MainViewModel MainPage::ViewModel() 22 | { 23 | return viewModel; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pages/MainPage.h: -------------------------------------------------------------------------------- 1 | // 2 | // Declaration of the MainPage class. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "MainPage.g.h" 8 | 9 | namespace winrt::MvvmCppWinRT::implementation 10 | { 11 | struct MainPage : MainPageT 12 | { 13 | MainPage(); 14 | 15 | MvvmCppWinRT::MainViewModel ViewModel(); 16 | 17 | private: 18 | MvvmCppWinRT::MainViewModel viewModel{ nullptr }; 19 | }; 20 | } 21 | 22 | namespace winrt::MvvmCppWinRT::factory_implementation 23 | { 24 | struct MainPage : MainPageT 25 | { 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /Pages/MainPage.idl: -------------------------------------------------------------------------------- 1 | // MainPage 2 | import "ViewModels/MainViewModel.idl"; 3 | 4 | namespace MvvmCppWinRT 5 | { 6 | [default_interface] 7 | runtimeclass MainPage : Windows.UI.Xaml.Controls.Page 8 | { 9 | MainPage(); 10 | MainViewModel ViewModel{ get; }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Pages/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 |