├── .github └── workflows │ └── build-publish.yml ├── .gitignore ├── LICENSE ├── Maui.ContentButton.sln ├── Maui.ContentButton ├── Apple │ ├── ContentButtonHandler.ios.maccatalyst.cs │ └── MauiAppleButton.ios.maccatalyst.cs ├── AssemblyInfo.cs ├── ContentButton.cs ├── ContentButtonHandler.cs ├── ContentButtonHandler.standard.cs ├── ContentButtonLayoutExtensions.cs ├── HostExtensions.cs ├── IContentButton.cs ├── IContentButtonHandler.cs ├── Maui.ContentButton.csproj └── Platforms │ ├── Android │ ├── ButtonExtensions.cs │ ├── ContentButtonHandler.android.cs │ ├── MauiMaterialCardView.android.cs │ └── MauiRippleDrawableExtensions.cs │ ├── Tizen │ └── PlatformClass1.cs │ └── Windows │ ├── ContentButtonExtensions.cs │ ├── ContentButtonHandler.windows.cs │ ├── MauiContentButton.windows.cs │ └── MauiContentButtonContent.windows.cs ├── NuGet.Config ├── README.md ├── Sample ├── App.xaml ├── App.xaml.cs ├── AppShell.xaml ├── AppShell.xaml.cs ├── MainPage.xaml ├── MainPage.xaml.cs ├── MauiProgram.cs ├── Platforms │ ├── Android │ │ ├── AndroidManifest.xml │ │ ├── MainActivity.cs │ │ ├── MainApplication.cs │ │ └── Resources │ │ │ └── values │ │ │ └── colors.xml │ ├── MacCatalyst │ │ ├── AppDelegate.cs │ │ ├── Entitlements.plist │ │ ├── Info.plist │ │ └── Program.cs │ ├── Tizen │ │ ├── Main.cs │ │ └── tizen-manifest.xml │ ├── Windows │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── Package.appxmanifest │ │ └── app.manifest │ └── iOS │ │ ├── AppDelegate.cs │ │ ├── Info.plist │ │ ├── Program.cs │ │ └── Resources │ │ └── PrivacyInfo.xcprivacy ├── Properties │ └── launchSettings.json ├── Resources │ ├── AppIcon │ │ ├── appicon.svg │ │ └── appiconfg.svg │ ├── Fonts │ │ ├── OpenSans-Regular.ttf │ │ └── OpenSans-Semibold.ttf │ ├── Images │ │ └── dotnet_bot.png │ ├── Raw │ │ └── AboutAssets.txt │ ├── Splash │ │ └── splash.svg │ └── Styles │ │ ├── Colors.xaml │ │ └── Styles.xaml └── Sample.csproj └── global.json /.github/workflows/build-publish.yml: -------------------------------------------------------------------------------- 1 | name: Build and Publish 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [ main ] 7 | release: 8 | types: [published] 9 | 10 | jobs: 11 | build: 12 | name: Build 13 | env: 14 | NUPKG_MAJOR: 0.999 15 | runs-on: windows-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v2 19 | - name: Setup .NET 20 | uses: actions/setup-dotnet@v3 21 | with: 22 | dotnet-version: 8.0.x 23 | - name: Setup Workloads 24 | run: dotnet workload install maui --version 8.0.407 25 | - name: Build 26 | run: dotnet build --configuration Release 27 | - name: Package NuGets 28 | shell: pwsh 29 | run: | 30 | $VERSION="$env:NUPKG_MAJOR-ci$env:GITHUB_RUN_ID" 31 | if ($env:GITHUB_EVENT_NAME -eq "release") { 32 | $VERSION = $env:GITHUB_REF.Substring($env:GITHUB_REF.LastIndexOf('/') + 1) 33 | } 34 | echo "::set-output name=pkgverci::$VERSION" 35 | echo "PACKAGE VERSION: $VERSION" 36 | 37 | New-Item -ItemType Directory -Force -Path .\artifacts 38 | dotnet pack --output ./artifacts --configuration Release -p:PackageVersion=$VERSION ./Maui.ContentButton/Maui.ContentButton.csproj 39 | 40 | - name: Artifacts 41 | uses: actions/upload-artifact@v4 42 | with: 43 | name: NuGet 44 | path: ./artifacts 45 | 46 | publish: 47 | name: Publish 48 | needs: build 49 | runs-on: windows-latest 50 | if: github.event_name == 'release' 51 | steps: 52 | - name: Download Artifacts 53 | uses: actions/download-artifact@v4 54 | with: 55 | name: NuGet 56 | - name: Setup .NET 57 | uses: actions/setup-dotnet@v3 58 | with: 59 | dotnet-version: '8.0.x' 60 | - name: Push NuGet 61 | run: | 62 | dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Jonathan Dick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Maui.ContentButton.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35221.11 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maui.ContentButton", "Maui.ContentButton\Maui.ContentButton.csproj", "{BA12F02A-2A4F-4382-A8FE-3096B61DC391}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 19 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {F604B49E-D1B8-4C57-A021-77C7D7BC0DFD}.Release|Any CPU.Deploy.0 = Release|Any CPU 22 | {BA12F02A-2A4F-4382-A8FE-3096B61DC391}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {BA12F02A-2A4F-4382-A8FE-3096B61DC391}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {BA12F02A-2A4F-4382-A8FE-3096B61DC391}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {BA12F02A-2A4F-4382-A8FE-3096B61DC391}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {15E58CCE-D772-4991-915E-4A40421CEF2A} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /Maui.ContentButton/Apple/ContentButtonHandler.ios.maccatalyst.cs: -------------------------------------------------------------------------------- 1 | #if IOS || MACCATALYST 2 | using Microsoft.Maui.Handlers; 3 | using Microsoft.Maui.Platform; 4 | using UIKit; 5 | using MButton = UIKit.UIButton; 6 | 7 | namespace MauiContentButton; 8 | 9 | public partial class ContentButtonHandler : ViewHandler 10 | { 11 | static readonly UIControlState[] ControlStates = { UIControlState.Normal, UIControlState.Highlighted, UIControlState.Disabled }; 12 | 13 | public readonly static Thickness DefaultPadding = new Thickness(12, 7); 14 | 15 | public const int ContentButtonHandlerContentViewTag = 23123; 16 | 17 | protected override UIButton CreatePlatformView() 18 | { 19 | var button = new MauiAppleButton { 20 | CrossPlatformLayout = VirtualView, 21 | ClipsToBounds = true, 22 | Configuration = UIButtonConfiguration.BorderlessButtonConfiguration, 23 | TouchesHandlers = new MauiAppleButtonTouches(VirtualView.Pressed, VirtualView.Released, VirtualView.Clicked) 24 | }; 25 | 26 | SetControlPropertiesFromProxy(button); 27 | 28 | return button; 29 | } 30 | 31 | 32 | 33 | public static void MapBackground(IContentButtonHandler handler, IContentButton button) 34 | { 35 | if (handler.PlatformView.Configuration is not null) 36 | { 37 | handler.PlatformView.UpdateBackground(button.Background, button); 38 | } 39 | } 40 | 41 | public static void MapStrokeColor(IContentButtonHandler handler, IButtonStroke buttonStroke) 42 | { 43 | if (handler.PlatformView.Configuration is not null) 44 | { 45 | handler.PlatformView.UpdateStrokeColor(buttonStroke); 46 | } 47 | } 48 | 49 | public static void MapStrokeThickness(IContentButtonHandler handler, IButtonStroke buttonStroke) 50 | { 51 | if (handler.PlatformView.Configuration is not null) 52 | { 53 | handler.PlatformView.UpdateStrokeThickness(buttonStroke); 54 | } 55 | } 56 | 57 | public static void MapCornerRadius(IContentButtonHandler handler, IButtonStroke buttonStroke) 58 | { 59 | if (handler.PlatformView.Configuration is not null) 60 | { 61 | handler.PlatformView.UpdateCornerRadius(buttonStroke); 62 | } 63 | } 64 | 65 | public static void MapPadding(IContentButtonHandler handler, IPadding padding) 66 | { 67 | handler.PlatformView?.UpdatePadding(padding.Padding, DefaultPadding); 68 | } 69 | 70 | static void SetControlPropertiesFromProxy(UIButton platformView) 71 | { 72 | foreach (UIControlState uiControlState in ControlStates) 73 | { 74 | platformView.SetBackgroundImage(UIButton.Appearance.BackgroundImageForState(uiControlState), uiControlState); 75 | } 76 | } 77 | 78 | public static void MapContent(IContentButtonHandler handler, IContentButton view) 79 | { 80 | _ = handler.PlatformView ?? throw new InvalidOperationException($"{nameof(PlatformView)} should have been set by base class."); 81 | _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); 82 | _ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class."); 83 | 84 | // Remove the known content subview (by tag) if it exists 85 | for (var i = 0; i < handler.PlatformView.Subviews.Length; i++) 86 | { 87 | var subview = handler.PlatformView.Subviews[i]; 88 | if (subview.Tag == ContentButtonHandlerContentViewTag) 89 | { 90 | subview.RemoveFromSuperview(); 91 | break; 92 | } 93 | } 94 | 95 | if (handler.VirtualView.PresentedContent is IView presentedView) 96 | { 97 | var inner = presentedView.ToPlatform(handler.MauiContext); 98 | inner.Tag = ContentButtonHandlerContentViewTag; 99 | handler.PlatformView.AddSubview(inner); 100 | } 101 | } 102 | } 103 | 104 | #endif -------------------------------------------------------------------------------- /Maui.ContentButton/Apple/MauiAppleButton.ios.maccatalyst.cs: -------------------------------------------------------------------------------- 1 | #if IOS || MACCATALYST 2 | using UIKit; 3 | using CoreGraphics; 4 | using Foundation; 5 | using Microsoft.Maui.Platform; 6 | 7 | namespace MauiContentButton; 8 | 9 | public class MauiAppleButton : UIButton, ICrossPlatformLayoutBacking 10 | { 11 | bool _fireSetNeedsLayoutOnParentWhenWindowAttached; 12 | 13 | double _lastMeasureHeight = double.NaN; 14 | double _lastMeasureWidth = double.NaN; 15 | 16 | WeakReference? _crossPlatformLayoutReference; 17 | 18 | public MauiAppleButtonTouches? TouchesHandlers { get; set; } 19 | 20 | protected bool IsMeasureValid(double widthConstraint, double heightConstraint) 21 | { 22 | // Check the last constraints this View was measured with; if they're the same, 23 | // then the current measure info is already correct and we don't need to repeat it 24 | return heightConstraint == _lastMeasureHeight && widthConstraint == _lastMeasureWidth; 25 | } 26 | 27 | protected void InvalidateConstraintsCache() 28 | { 29 | _lastMeasureWidth = double.NaN; 30 | _lastMeasureHeight = double.NaN; 31 | } 32 | 33 | protected void CacheMeasureConstraints(double widthConstraint, double heightConstraint) 34 | { 35 | _lastMeasureWidth = widthConstraint; 36 | _lastMeasureHeight = heightConstraint; 37 | } 38 | 39 | public ICrossPlatformLayout? CrossPlatformLayout 40 | { 41 | get => _crossPlatformLayoutReference != null && _crossPlatformLayoutReference.TryGetTarget(out var v) ? v : null; 42 | set => _crossPlatformLayoutReference = value == null ? null : new WeakReference(value); 43 | } 44 | 45 | Size CrossPlatformMeasure(double widthConstraint, double heightConstraint) 46 | { 47 | return CrossPlatformLayout?.CrossPlatformMeasure(widthConstraint, heightConstraint) ?? Size.Zero; 48 | } 49 | 50 | Size CrossPlatformArrange(Rect bounds) 51 | { 52 | return CrossPlatformLayout?.CrossPlatformArrange(bounds) ?? Size.Zero; 53 | } 54 | 55 | public override CGSize SizeThatFits(CGSize size) 56 | { 57 | if (_crossPlatformLayoutReference == null) 58 | { 59 | return base.SizeThatFits(size); 60 | } 61 | 62 | var widthConstraint = size.Width; 63 | var heightConstraint = size.Height; 64 | 65 | var crossPlatformSize = CrossPlatformMeasure(widthConstraint, heightConstraint); 66 | 67 | CacheMeasureConstraints(widthConstraint, heightConstraint); 68 | 69 | return crossPlatformSize.ToCGSize(); 70 | } 71 | 72 | // TODO: Possibly reconcile this code with ViewHandlerExtensions.LayoutVirtualView 73 | // If you make changes here please review if those changes should also 74 | // apply to ViewHandlerExtensions.LayoutVirtualView 75 | public override void LayoutSubviews() 76 | { 77 | base.LayoutSubviews(); 78 | 79 | if (_crossPlatformLayoutReference == null) 80 | { 81 | return; 82 | } 83 | 84 | var bounds = Bounds.ToRectangle(); 85 | 86 | var widthConstraint = bounds.Width; 87 | var heightConstraint = bounds.Height; 88 | 89 | // If the SuperView is a MauiView (backing a cross-platform ContentView or Layout), then measurement 90 | // has already happened via SizeThatFits and doesn't need to be repeated in LayoutSubviews. But we 91 | // _do_ need LayoutSubviews to make a measurement pass if the parent is something else (for example, 92 | // the window); there's no guarantee that SizeThatFits has been called in that case. 93 | 94 | if (!IsMeasureValid(widthConstraint, heightConstraint) && Superview is not MauiView) 95 | { 96 | CrossPlatformMeasure(widthConstraint, heightConstraint); 97 | CacheMeasureConstraints(widthConstraint, heightConstraint); 98 | } 99 | 100 | CrossPlatformArrange(bounds); 101 | } 102 | 103 | public override void SetNeedsLayout() 104 | { 105 | InvalidateConstraintsCache(); 106 | base.SetNeedsLayout(); 107 | TryToInvalidateSuperView(false); 108 | } 109 | 110 | private protected void TryToInvalidateSuperView(bool shouldOnlyInvalidateIfPending) 111 | { 112 | if (shouldOnlyInvalidateIfPending && !_fireSetNeedsLayoutOnParentWhenWindowAttached) 113 | { 114 | return; 115 | } 116 | 117 | // We check for Window to avoid scenarios where an invalidate might propagate up the tree 118 | // To a SuperView that's been disposed which will cause a crash when trying to access it 119 | if (Window is not null) 120 | { 121 | this.Superview?.SetNeedsLayout(); 122 | _fireSetNeedsLayoutOnParentWhenWindowAttached = false; 123 | } 124 | else 125 | { 126 | _fireSetNeedsLayoutOnParentWhenWindowAttached = true; 127 | } 128 | } 129 | 130 | public override void MovedToWindow() 131 | { 132 | base.MovedToWindow(); 133 | //_movedToWindow?.Invoke(this, EventArgs.Empty); 134 | TryToInvalidateSuperView(true); 135 | } 136 | 137 | 138 | public override void TouchesBegan(NSSet touches, UIEvent? evt) 139 | { 140 | base.TouchesBegan(touches, evt); 141 | 142 | TouchesHandlers?.PressedHandler?.Invoke(); 143 | } 144 | 145 | public override void TouchesEnded(NSSet touches, UIEvent? evt) 146 | { 147 | base.TouchesEnded(touches, evt); 148 | 149 | TouchesHandlers?.ReleasedHandler?.Invoke(); 150 | 151 | if (touches?.FirstOrDefault() is UITouch touch) 152 | { 153 | var point = touch.LocationInView(this); 154 | if (this.PointInside(point, evt)) { 155 | // didTouchUpInside 156 | TouchesHandlers?.ClickedHandler?.Invoke(); 157 | } 158 | } 159 | } 160 | } 161 | 162 | public record MauiAppleButtonTouches(Action PressedHandler, Action ReleasedHandler, Action ClickedHandler) 163 | { 164 | } 165 | #endif 166 | -------------------------------------------------------------------------------- /Maui.ContentButton/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | [assembly: XmlnsDefinition(MauiContentButton.Constants.XamlNamespace, MauiContentButton.Constants.MauiContentButtonNamespace)] 2 | 3 | [assembly: Microsoft.Maui.Controls.XmlnsPrefix(MauiContentButton.Constants.XamlNamespace, "contentbutton")] 4 | 5 | namespace MauiContentButton; 6 | 7 | static class Constants 8 | { 9 | public const string XamlNamespace = "http://schemas.microsoft.com/dotnet/2024/maui/contentbutton"; 10 | public const string MauiContentButtonNamespace = $"{nameof(MauiContentButton)}"; 11 | } -------------------------------------------------------------------------------- /Maui.ContentButton/ContentButton.cs: -------------------------------------------------------------------------------- 1 | #if WINDOWS 2 | #elif ANDROID 3 | using PlatformButtonView = Android.Widget.Button; 4 | #elif IOS || MACCATALYST 5 | using PlatformButtonView = UIKit.UIButton; 6 | #else 7 | using PlatformButtonView = object; 8 | #endif 9 | 10 | using System.Windows.Input; 11 | 12 | 13 | namespace MauiContentButton; 14 | 15 | [ContentProperty(nameof(Content))] 16 | public class ContentButton : View, IContentButton, ICrossPlatformLayout 17 | { 18 | 19 | /// Bindable property for . 20 | public static readonly BindableProperty ContentProperty 21 | = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentView), null, 22 | propertyChanged: (bindableObject, oldValue, newValue) => 23 | { 24 | if (bindableObject is ContentButton contentButton) 25 | { 26 | 27 | if (oldValue is View oldView) 28 | { 29 | contentButton.RemoveLogicalChild(oldView); 30 | } 31 | 32 | if (newValue is View newView) 33 | { 34 | contentButton.AddLogicalChild(newView); 35 | } 36 | } 37 | }); 38 | 39 | public View Content 40 | { 41 | get { return (View)GetValue(ContentProperty); } 42 | set { SetValue(ContentProperty, value); } 43 | } 44 | 45 | protected override void OnBindingContextChanged() 46 | { 47 | base.OnBindingContextChanged(); 48 | 49 | IView content = Content; 50 | 51 | if (content == null && (this as IContentView)?.PresentedContent is IView presentedContent) 52 | content = presentedContent; 53 | 54 | if (content is BindableObject bindableContent) 55 | bindableContent.BindingContext = BindingContext; 56 | } 57 | 58 | object IContentButton.Content => Content; 59 | 60 | IView IContentButton.PresentedContent => Content; 61 | 62 | 63 | public static readonly BindableProperty PaddingProperty = 64 | BindableProperty.Create(nameof(Padding), typeof(Thickness), typeof(ContentButton), new Thickness(), 65 | propertyChanged: (bindable, oldValue, newValue) => 66 | { 67 | if (bindable is ContentButton contentButton) 68 | { 69 | contentButton.InvalidateMeasure(); 70 | } 71 | }); 72 | 73 | public Thickness Padding 74 | { 75 | get => (Thickness)GetValue(PaddingProperty); 76 | set => SetValue(PaddingProperty, value); 77 | } 78 | 79 | public const int DefaultCornerRadius = -1; 80 | 81 | public static readonly BindableProperty StrokeColorProperty = 82 | BindableProperty.Create(nameof(IButtonStroke.StrokeColor), typeof(Color), typeof(IButtonStroke), null); 83 | 84 | public static readonly BindableProperty StrokeThicknessProperty = 85 | BindableProperty.Create(nameof(IButtonStroke.StrokeThickness), typeof(double), typeof(IButtonStroke), -1d); 86 | 87 | public static readonly BindableProperty CornerRadiusProperty = 88 | BindableProperty.Create(nameof(IButtonStroke.CornerRadius), typeof(int), typeof(IButtonStroke), 89 | defaultValue: DefaultCornerRadius); 90 | 91 | public Color StrokeColor 92 | { 93 | get => (Color)GetValue(StrokeColorProperty); 94 | set => SetValue(StrokeColorProperty, value); 95 | } 96 | 97 | public double StrokeThickness 98 | { 99 | get => (double)GetValue(StrokeThicknessProperty); 100 | set => SetValue(StrokeThicknessProperty, value); 101 | } 102 | 103 | public int CornerRadius 104 | { 105 | get => (int)GetValue(CornerRadiusProperty); 106 | set => SetValue(CornerRadiusProperty, value); 107 | } 108 | 109 | static readonly BindablePropertyKey IsPressedPropertyKey = 110 | BindableProperty.CreateReadOnly(nameof(IsPressed), typeof(bool), typeof(ContentButton), default(bool)); 111 | 112 | public static readonly BindableProperty IsPressedProperty = IsPressedPropertyKey.BindableProperty; 113 | 114 | public bool IsPressed => (bool)GetValue(IsPressedProperty); 115 | 116 | void IContentButton.Clicked() 117 | { 118 | if (IsEnabled) 119 | { 120 | this.ChangeVisualState(); 121 | Clicked?.Invoke(this, EventArgs.Empty); 122 | Command?.Execute(CommandParameter); 123 | } 124 | } 125 | 126 | void IContentButton.Pressed() 127 | { 128 | SetValue(IsPressedPropertyKey, true); 129 | ChangeVisualState(); 130 | Pressed?.Invoke(this, EventArgs.Empty); 131 | } 132 | 133 | void IContentButton.Released() 134 | { 135 | SetValue(IsPressedPropertyKey, false); 136 | ChangeVisualState(); 137 | Released?.Invoke(this, EventArgs.Empty); 138 | } 139 | 140 | /// 141 | /// Occurs when the button is clicked/tapped. 142 | /// 143 | public event EventHandler Clicked; 144 | 145 | /// 146 | /// Occurs when the button is pressed. 147 | /// 148 | public event EventHandler Pressed; 149 | 150 | /// 151 | /// Occurs when the button is released. 152 | /// 153 | public event EventHandler Released; 154 | 155 | public const string PressedVisualState = "Pressed"; 156 | 157 | 158 | protected override void ChangeVisualState() 159 | { 160 | if (IsEnabled && IsPressed) 161 | { 162 | VisualStateManager.GoToState(this, PressedVisualState); 163 | } 164 | else 165 | { 166 | base.ChangeVisualState(); 167 | } 168 | } 169 | 170 | public static readonly BindableProperty CommandProperty = BindableProperty.Create( 171 | nameof(Command), typeof(ICommand), typeof(ContentButton), null); 172 | 173 | public ICommand Command 174 | { 175 | get => (ICommand)GetValue(CommandProperty); 176 | set => SetValue(CommandProperty, value); 177 | } 178 | 179 | public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create( 180 | nameof(CommandParameter), typeof(object), typeof(ContentButton), null); 181 | 182 | public object CommandParameter 183 | { 184 | get => GetValue(CommandParameterProperty); 185 | set => SetValue(CommandParameterProperty, value); 186 | } 187 | 188 | public Size CrossPlatformArrange(Rect bounds) 189 | { 190 | var inset = bounds.Inset(StrokeThickness); 191 | this.ArrangeContent(inset); 192 | return bounds.Size; 193 | } 194 | 195 | public Size CrossPlatformMeasure(double widthConstraint, double heightConstraint) 196 | { 197 | var inset = Padding + StrokeThickness; 198 | return this.MeasureContent( inset, widthConstraint, heightConstraint); 199 | } 200 | } -------------------------------------------------------------------------------- /Maui.ContentButton/ContentButtonHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Handlers; 2 | using Microsoft.Maui.Platform; 3 | 4 | 5 | #if WINDOWS 6 | using PlatformButtonView = Microsoft.Maui.Platform.MauiButton; 7 | #elif ANDROID 8 | using PlatformButtonView = MauiContentButton.MauiMaterialCardView; 9 | #elif IOS || MACCATALYST 10 | using PlatformButtonView = UIKit.UIButton; 11 | #else 12 | using PlatformButtonView = object; 13 | #endif 14 | 15 | namespace MauiContentButton; 16 | 17 | 18 | // All the code in this file is included in all platforms. 19 | public partial class ContentButtonHandler : IContentButtonHandler 20 | { 21 | public static IPropertyMapper Mapper = new PropertyMapper(ViewMapper, ViewHandler.ViewMapper) 22 | { 23 | [nameof(IPadding.Padding)] = MapPadding, 24 | [nameof(IButtonStroke.StrokeThickness)] = MapStrokeThickness, 25 | [nameof(IButtonStroke.StrokeColor)] = MapStrokeColor, 26 | [nameof(IButtonStroke.CornerRadius)] = MapCornerRadius, 27 | [nameof(IContentButton.Content)] = MapContent, 28 | 29 | #if ANDROID || MACCATALYST || WINDOWS || IOS 30 | [nameof(IContentButton.Background)] = MapBackground, 31 | #endif 32 | }; 33 | 34 | public static CommandMapper CommandMapper = new(ViewCommandMapper); 35 | 36 | public ContentButtonHandler() 37 | : base(Mapper, CommandMapper) 38 | { 39 | 40 | } 41 | 42 | public ContentButtonHandler(IPropertyMapper? mapper) 43 | : base(mapper ?? Mapper, CommandMapper) 44 | { 45 | } 46 | 47 | public ContentButtonHandler(IPropertyMapper? mapper, CommandMapper? commandMapper) 48 | : base(mapper ?? Mapper, commandMapper ?? CommandMapper) 49 | { 50 | } 51 | 52 | IContentButton IContentButtonHandler.VirtualView => VirtualView; 53 | 54 | PlatformButtonView IContentButtonHandler.PlatformView => PlatformView; 55 | } 56 | -------------------------------------------------------------------------------- /Maui.ContentButton/ContentButtonHandler.standard.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Handlers; 2 | using PlatformButtonView = object; 3 | 4 | namespace MauiContentButton; 5 | 6 | // All the code in this file is included in all platforms. 7 | public partial class ContentButtonHandler : ViewHandler 8 | { 9 | protected override PlatformButtonView CreatePlatformView() => new(); 10 | 11 | private static void MapPadding(IContentButtonHandler handler, IContentButton view) { } 12 | 13 | private static void MapStrokeThickness(IContentButtonHandler handler, IContentButton view) { } 14 | 15 | private static void MapStrokeColor(IContentButtonHandler handler, IContentButton view) { } 16 | 17 | private static void MapCornerRadius(IContentButtonHandler handler, IContentButton view) { } 18 | 19 | private static void MapContent(IContentButtonHandler handler, IContentButton view) { } 20 | } 21 | -------------------------------------------------------------------------------- /Maui.ContentButton/ContentButtonLayoutExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Primitives; 2 | 3 | namespace MauiContentButton; 4 | 5 | // These are mirrors of the LayoutExtensions in MAUI Core but those take IContentView so aren't usable here 6 | public static class ContentButtonLayoutExtensions 7 | { 8 | public static Size MeasureContent(this IContentButton contentButton, Thickness inset, double widthConstraint, double heightConstraint) 9 | { 10 | var content = contentButton.PresentedContent; 11 | 12 | if (Dimension.IsExplicitSet(contentButton.Width)) 13 | { 14 | widthConstraint = contentButton.Width; 15 | } 16 | 17 | if (Dimension.IsExplicitSet(contentButton.Height)) 18 | { 19 | heightConstraint = contentButton.Height; 20 | } 21 | 22 | var contentSize = Size.Zero; 23 | 24 | if (content != null) 25 | { 26 | contentSize = content.Measure(widthConstraint - inset.HorizontalThickness, 27 | heightConstraint - inset.VerticalThickness); 28 | } 29 | 30 | return new Size(contentSize.Width + inset.HorizontalThickness, contentSize.Height + inset.VerticalThickness); 31 | } 32 | 33 | public static void ArrangeContent(this IContentButton contentButton, Rect bounds) 34 | { 35 | if (contentButton.PresentedContent == null) 36 | { 37 | return; 38 | } 39 | 40 | var padding = contentButton.Padding; 41 | 42 | var targetBounds = new Rect(bounds.Left + padding.Left, bounds.Top + padding.Top, 43 | bounds.Width - padding.HorizontalThickness, bounds.Height - padding.VerticalThickness); 44 | 45 | _ = contentButton.PresentedContent.Arrange(targetBounds); 46 | } 47 | 48 | public static Rect Inset(this Rect rectangle, double inset) 49 | { 50 | if (inset == 0) 51 | { 52 | return rectangle; 53 | } 54 | 55 | return new Rect(rectangle.Left + inset, rectangle.Top + inset, 56 | rectangle.Width - (2 * inset), rectangle.Height - (2 * inset)); 57 | } 58 | } -------------------------------------------------------------------------------- /Maui.ContentButton/HostExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MauiContentButton; 8 | 9 | public static class MauiContentButtonHostExtensions 10 | { 11 | 12 | public static IMauiHandlersCollection AddMauiContentButtonHandler(this IMauiHandlersCollection handlersCollection) 13 | { 14 | handlersCollection.AddHandler(); 15 | 16 | return handlersCollection; 17 | } 18 | 19 | public static MauiAppBuilder AddMauiContentButtonHandler(this MauiAppBuilder builder) 20 | { 21 | builder.ConfigureMauiHandlers(handlers => handlers.AddMauiContentButtonHandler()); 22 | 23 | return builder; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Maui.ContentButton/IContentButton.cs: -------------------------------------------------------------------------------- 1 | #if WINDOWS 2 | #elif ANDROID 3 | using PlatformButtonView = Android.Widget.Button; 4 | #elif IOS || MACCATALYST 5 | using PlatformButtonView = UIKit.UIButton; 6 | #else 7 | using PlatformButtonView = object; 8 | #endif 9 | 10 | namespace MauiContentButton; 11 | 12 | public interface IContentButton : IView, IButtonStroke, ICrossPlatformLayout, IPadding 13 | { 14 | /// 15 | /// Occurs when the button is pressed. 16 | /// 17 | void Pressed(); 18 | 19 | /// 20 | /// Occurs when the button is released. 21 | /// 22 | void Released(); 23 | 24 | /// 25 | /// Occurs when the button is clicked/tapped. 26 | /// 27 | void Clicked(); 28 | 29 | /// 30 | /// Gets the raw content of this view. 31 | /// 32 | object? Content { get; } 33 | 34 | /// 35 | /// Gets the content of this view as it will be rendered in the user interface, including any transformations or applied templates. 36 | /// 37 | IView? PresentedContent { get; } 38 | 39 | /// 40 | /// This interface method is provided for backward compatibility with previous versions. 41 | /// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method. 42 | /// 43 | new Size CrossPlatformMeasure(double widthConstraint, double heightConstraint) 44 | => (Content as IView)?.Measure(widthConstraint, heightConstraint) ?? Size.Zero; 45 | 46 | /// 47 | /// This interface method is provided for backward compatibility with previous versions. 48 | /// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method. 49 | /// 50 | new Size CrossPlatformArrange(Rect bounds) 51 | => (Content as IView)?.Arrange(bounds) ?? Size.Zero; 52 | 53 | #if !NETSTANDARD2_0 54 | Size ICrossPlatformLayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) 55 | => CrossPlatformArrange(bounds); 56 | Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) 57 | => CrossPlatformMeasure(widthConstraint, heightConstraint); 58 | #endif 59 | } 60 | -------------------------------------------------------------------------------- /Maui.ContentButton/IContentButtonHandler.cs: -------------------------------------------------------------------------------- 1 | #if WINDOWS 2 | using PlatformButtonView = Microsoft.Maui.Platform.MauiButton; 3 | #elif ANDROID 4 | using PlatformButtonView = MauiContentButton.MauiMaterialCardView; 5 | #elif IOS || MACCATALYST 6 | using PlatformButtonView = UIKit.UIButton; 7 | #else 8 | using PlatformButtonView = object; 9 | #endif 10 | 11 | namespace MauiContentButton; 12 | 13 | public interface IContentButtonHandler : IViewHandler 14 | { 15 | new PlatformButtonView PlatformView { get; } 16 | new IContentButton VirtualView { get; } 17 | } 18 | -------------------------------------------------------------------------------- /Maui.ContentButton/Maui.ContentButton.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst 5 | $(TargetFrameworks);net8.0-windows10.0.19041.0 6 | 7 | 8 | true 9 | true 10 | enable 11 | enable 12 | 13 | 15.0 14 | 15.0 15 | 21.0 16 | 10.0.17763.0 17 | 10.0.17763.0 18 | 6.5 19 | 20 | 21 | 22 | Plugin.Maui.ContentButton 23 | ContentButton for .NET MAUI 24 | ContentButton which allows you to nest any MAUI view(s) inside of it 25 | Redth 26 | Redth 27 | Copyright © Redth 28 | https://github.com/redth/Maui.ContentButton 29 | MIT 30 | https://github.com/redth/Maui.ContentButton 31 | $(PackageVersion) 32 | true 33 | snupkg 34 | portable 35 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb 36 | 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Android/ButtonExtensions.cs: -------------------------------------------------------------------------------- 1 | using Google.Android.Material.Button; 2 | using AColor = Android.Graphics.Color; 3 | using R = Android.Resource; 4 | using MauiContentButton; 5 | using Google.Android.Material.Card; 6 | using Microsoft.Maui.Controls.Compatibility.Platform.Android; 7 | 8 | namespace Maui.ContentButton; 9 | 10 | internal static class ButtonExtensions 11 | { 12 | internal static void UpdateButtonStroke(this MaterialCardView platformView, IButtonStroke buttonStroke) 13 | { 14 | if (!platformView.UpdateMauiRippleDrawableStroke(buttonStroke)) 15 | { 16 | // Fall back to the default mechanism. This may be due to the fact that the background 17 | // is not a "MAUI" background, so we need to update the stroke on the button itself. 18 | 19 | var (width, color, radius) = buttonStroke.GetStrokeProperties(platformView.Context!, true); 20 | 21 | platformView.SetStrokeColor(color); 22 | 23 | platformView.StrokeWidth = width; 24 | 25 | platformView.Radius = radius; 26 | } 27 | } 28 | 29 | internal static void UpdateButtonBackground(this MaterialCardView platformView, IContentButton button) 30 | { 31 | platformView.UpdateMauiRippleDrawableBackground( 32 | button.Background, 33 | button, 34 | () => 35 | { 36 | // Copy the tints from a temporary button. 37 | // TODO: optimize this to avoid creating a new button every time. 38 | 39 | var context = platformView.Context!; 40 | using var btn = new MaterialButton(context); 41 | var defaultTintList = btn.BackgroundTintList; 42 | var defaultColor = defaultTintList?.GetColorForState([R.Attribute.StateEnabled], AColor.Black); 43 | 44 | return defaultColor ?? AColor.Black; 45 | }, 46 | () => 47 | { 48 | // If some theme or user value has been set, we can override the default, white 49 | // ripple color using this button property. 50 | return platformView.RippleColor; 51 | }, 52 | () => 53 | { 54 | // We have a background, so we need to null out the tint list to avoid the tint 55 | // overriding the background. 56 | platformView.BackgroundTintList = null; 57 | }); 58 | } 59 | } -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Android/ContentButtonHandler.android.cs: -------------------------------------------------------------------------------- 1 | using Android.Views; 2 | using Google.Android.Material.Shape; 3 | using Maui.ContentButton; 4 | using Microsoft.Maui.Controls.Compatibility.Platform.Android; 5 | using Microsoft.Maui.Controls.Platform; 6 | using Microsoft.Maui.Handlers; 7 | using Microsoft.Maui.Platform; 8 | using AButton = MauiContentButton.MauiMaterialCardView; 9 | using AView = Android.Views.View; 10 | 11 | namespace MauiContentButton; 12 | 13 | // All the code in this file is only included on Windows. 14 | public partial class ContentButtonHandler : ViewHandler 15 | { 16 | protected override AButton CreatePlatformView() 17 | { 18 | if (VirtualView == null) 19 | { 20 | throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a LayoutView"); 21 | } 22 | 23 | var materialCard = new MauiMaterialCardView(Context) 24 | { 25 | CrossPlatformLayout = VirtualView 26 | }; 27 | 28 | materialCard.CardElevation = 0f; 29 | materialCard.SetClipChildren(true); 30 | 31 | return materialCard; 32 | } 33 | 34 | ButtonClickListener ClickListener { get; } = new ButtonClickListener(); 35 | ButtonTouchListener TouchListener { get; } = new ButtonTouchListener(); 36 | 37 | 38 | protected override void ConnectHandler(AButton platformView) 39 | { 40 | ClickListener.Handler = this; 41 | platformView.SetOnClickListener(ClickListener); 42 | 43 | TouchListener.Handler = this; 44 | platformView.SetOnTouchListener(TouchListener); 45 | 46 | platformView.FocusChange += OnNativeViewFocusChange; 47 | platformView.LayoutChange += OnPlatformViewLayoutChange; 48 | 49 | base.ConnectHandler(platformView); 50 | } 51 | 52 | 53 | protected override void DisconnectHandler(AButton platformView) 54 | { 55 | platformView.CrossPlatformLayout = null; 56 | platformView.RemoveAllViews(); 57 | 58 | ClickListener.Handler = null; 59 | platformView.SetOnClickListener(null); 60 | 61 | TouchListener.Handler = null; 62 | platformView.SetOnTouchListener(null); 63 | 64 | platformView.FocusChange -= OnNativeViewFocusChange; 65 | platformView.LayoutChange -= OnPlatformViewLayoutChange; 66 | 67 | base.DisconnectHandler(platformView); 68 | } 69 | 70 | public static void MapContent(IContentButtonHandler handler, IContentButton view) 71 | { 72 | _ = handler.PlatformView ?? throw new InvalidOperationException($"{nameof(PlatformView)} should have been set by base class."); 73 | _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); 74 | _ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class."); 75 | 76 | if (handler.PlatformView is not null) 77 | { 78 | handler.PlatformView.RemoveAllViews(); 79 | 80 | if (handler.VirtualView.PresentedContent is IView presentedView) 81 | handler.PlatformView.AddView(presentedView.ToPlatform(handler.MauiContext)); 82 | } 83 | } 84 | 85 | public static void MapBackground(IContentButtonHandler handler, IContentButton view) 86 | { 87 | // TODO: Handle more complex backgrounds than a single color (eg: gradient) 88 | if (handler.PlatformView is not null && view.Background is not null) 89 | { 90 | handler.PlatformView.UpdateButtonBackground(view); 91 | //handler.PlatformView.SetBackground(view.Background.ToDrawable(handler.MauiContext.Context)); 92 | //handler.PlatformView.SetCardBackgroundColor(view.Background.ToColor().ToAndroid()); 93 | } 94 | } 95 | 96 | public static void MapStrokeColor(IContentButtonHandler handler, IButtonStroke buttonStroke) 97 | { 98 | if (handler.PlatformView is not null && buttonStroke.StrokeColor is not null) 99 | handler.PlatformView.UpdateButtonStroke(buttonStroke); 100 | //handler.PlatformView.StrokeColor = buttonStroke.StrokeColor.ToAndroid(); 101 | } 102 | 103 | public static void MapStrokeThickness(IContentButtonHandler handler, IButtonStroke buttonStroke) 104 | { 105 | if (handler.PlatformView is not null) 106 | { 107 | handler.PlatformView.UpdateButtonStroke(buttonStroke); 108 | // var density = handler.PlatformView.Resources?.DisplayMetrics?.Density ?? 1f; 109 | // handler.PlatformView.StrokeWidth = (int)Math.Ceiling(buttonStroke.StrokeThickness * density); 110 | } 111 | } 112 | 113 | public static void MapCornerRadius(IContentButtonHandler handler, IButtonStroke buttonStroke) 114 | { 115 | if (handler.PlatformView is not null) 116 | { 117 | var density = (handler.PlatformView.Resources?.DisplayMetrics?.Density ?? 1f); 118 | 119 | handler.PlatformView.ShapeAppearanceModel = handler.PlatformView.ShapeAppearanceModel.ToBuilder() 120 | .SetAllCorners(CornerFamily.Rounded, density * buttonStroke.CornerRadius).Build(); 121 | } 122 | } 123 | 124 | public static void MapPadding(IContentButtonHandler handler, IPadding padding) 125 | { 126 | if (handler.PlatformView is not null) 127 | { 128 | var density = (handler.PlatformView.Resources?.DisplayMetrics?.Density ?? 1f); 129 | handler.PlatformView.SetContentPadding( 130 | (int)(padding.Padding.Left * density), 131 | (int)(padding.Padding.Top * density), 132 | (int)(padding.Padding.Right * density), 133 | (int)(padding.Padding.Bottom * density)); 134 | } 135 | } 136 | 137 | static bool OnTouch(IContentButton? button, AView? v, MotionEvent? e) 138 | { 139 | switch (e?.ActionMasked) 140 | { 141 | case MotionEventActions.Down: 142 | button?.Pressed(); 143 | break; 144 | case MotionEventActions.Cancel: 145 | case MotionEventActions.Up: 146 | button?.Released(); 147 | break; 148 | } 149 | 150 | return false; 151 | } 152 | 153 | static void OnClick(IContentButton? button, AView? v) 154 | { 155 | button?.Clicked(); 156 | } 157 | 158 | void OnNativeViewFocusChange(object? sender, AView.FocusChangeEventArgs e) 159 | { 160 | if (VirtualView != null) 161 | VirtualView.IsFocused = e.HasFocus; 162 | } 163 | 164 | void OnPlatformViewLayoutChange(object? sender, AView.LayoutChangeEventArgs e) 165 | { 166 | // TODO: 167 | } 168 | 169 | class ButtonClickListener : Java.Lang.Object, Android.Views.View.IOnClickListener 170 | { 171 | public ContentButtonHandler? Handler { get; set; } 172 | 173 | public void OnClick(Android.Views.View? v) 174 | { 175 | ContentButtonHandler.OnClick(Handler?.VirtualView, v); 176 | } 177 | } 178 | 179 | class ButtonTouchListener : Java.Lang.Object, AView.IOnTouchListener 180 | { 181 | public ContentButtonHandler? Handler { get; set; } 182 | 183 | public bool OnTouch(AView? v, global::Android.Views.MotionEvent? e) => 184 | ContentButtonHandler.OnTouch(Handler?.VirtualView, v, e); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Android/MauiMaterialCardView.android.cs: -------------------------------------------------------------------------------- 1 | using Android.Content; 2 | using Android.Runtime; 3 | using Android.Util; 4 | using Android.Views; 5 | using Google.Android.Material.Card; 6 | using Microsoft.Maui.Platform; 7 | 8 | namespace MauiContentButton; 9 | 10 | public class MauiMaterialCardView : MaterialCardView, ICrossPlatformLayoutBacking 11 | { 12 | readonly Context _context; 13 | 14 | public MauiMaterialCardView(Context context) : base(context) 15 | { 16 | _context = context; 17 | } 18 | 19 | public MauiMaterialCardView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) 20 | { 21 | var context = Context; 22 | ArgumentNullException.ThrowIfNull(context); 23 | _context = context; 24 | } 25 | 26 | public MauiMaterialCardView(Context context, IAttributeSet attrs) : base(context, attrs) 27 | { 28 | _context = context; 29 | } 30 | 31 | public MauiMaterialCardView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) 32 | { 33 | _context = context; 34 | } 35 | 36 | public ICrossPlatformLayout? CrossPlatformLayout 37 | { 38 | get; set; 39 | } 40 | 41 | Microsoft.Maui.Graphics.Size CrossPlatformMeasure(double widthConstraint, double heightConstraint) 42 | { 43 | return CrossPlatformLayout?.CrossPlatformMeasure(widthConstraint, heightConstraint) ?? Microsoft.Maui.Graphics.Size.Zero; 44 | } 45 | 46 | Microsoft.Maui.Graphics.Size CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) 47 | { 48 | return CrossPlatformLayout?.CrossPlatformArrange(bounds) ?? Microsoft.Maui.Graphics.Size.Zero; 49 | } 50 | 51 | protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 52 | { 53 | if (CrossPlatformMeasure == null) 54 | { 55 | base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 56 | return; 57 | } 58 | 59 | var deviceIndependentWidth = widthMeasureSpec.ToDouble(_context); 60 | var deviceIndependentHeight = heightMeasureSpec.ToDouble(_context); 61 | 62 | var widthMode = MeasureSpec.GetMode(widthMeasureSpec); 63 | var heightMode = MeasureSpec.GetMode(heightMeasureSpec); 64 | 65 | var measure = CrossPlatformMeasure(deviceIndependentWidth, deviceIndependentHeight); 66 | 67 | // If the measure spec was exact, we should return the explicit size value, even if the content 68 | // measure came out to a different size 69 | var width = widthMode == MeasureSpecMode.Exactly ? deviceIndependentWidth : measure.Width; 70 | var height = heightMode == MeasureSpecMode.Exactly ? deviceIndependentHeight : measure.Height; 71 | 72 | var platformWidth = _context.ToPixels(width); 73 | var platformHeight = _context.ToPixels(height); 74 | 75 | // Minimum values win over everything 76 | platformWidth = Math.Max(MinimumWidth, platformWidth); 77 | platformHeight = Math.Max(MinimumHeight, platformHeight); 78 | 79 | SetMeasuredDimension((int)platformWidth, (int)platformHeight); 80 | } 81 | 82 | protected override void OnLayout(bool changed, int left, int top, int right, int bottom) 83 | { 84 | if (CrossPlatformArrange == null) 85 | { 86 | return; 87 | } 88 | 89 | var destination = _context.ToCrossPlatformRectInReferenceFrame( 90 | left, 91 | top, 92 | right, 93 | bottom); 94 | 95 | CrossPlatformArrange(destination); 96 | } 97 | } -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Android/MauiRippleDrawableExtensions.cs: -------------------------------------------------------------------------------- 1 | using Android.Content; 2 | using Android.Content.Res; 3 | using AView = Android.Views.View; 4 | using System.Reflection; 5 | using Microsoft.Maui; 6 | 7 | namespace Maui.ContentButton; 8 | 9 | internal static class MauiRippleDrawableExtensions 10 | { 11 | static readonly Assembly parentAssembly = typeof(Microsoft.Maui.Platform.ButtonExtensions).Assembly; 12 | 13 | static Type? mauiRippleDrawableExtensionsType; 14 | 15 | static Type? MauiRippleDrawableExtensionsType 16 | => mauiRippleDrawableExtensionsType ??= parentAssembly.GetType("Microsoft.Maui.Platform.MauiRippleDrawableExtensions"); 17 | 18 | static MethodInfo? updateMauiRippleDrawableStrokeMethod; 19 | 20 | internal static bool UpdateMauiRippleDrawableStroke(this AView platformView, IButtonStroke buttonStroke) 21 | { 22 | updateMauiRippleDrawableStrokeMethod 23 | ??= MauiRippleDrawableExtensionsType?.GetMethod(nameof(UpdateMauiRippleDrawableStroke), BindingFlags.Static | BindingFlags.NonPublic); 24 | 25 | if (updateMauiRippleDrawableStrokeMethod is not null) 26 | { 27 | var r = updateMauiRippleDrawableStrokeMethod?.Invoke(null, [platformView, buttonStroke]); 28 | if (r is not null) 29 | return (bool)r; 30 | } 31 | 32 | return false; 33 | } 34 | 35 | 36 | static MethodInfo? updateMauiRippleDrawableBackgroundMethod; 37 | 38 | internal static void UpdateMauiRippleDrawableBackground(this AView platformView, 39 | Paint? background, 40 | IButtonStroke stroke, 41 | Func? getEmptyBackgroundColor = null, 42 | Func? getDefaultRippleColor = null, 43 | Action? beforeSet = null) 44 | { 45 | updateMauiRippleDrawableBackgroundMethod 46 | ??= MauiRippleDrawableExtensionsType?.GetMethod(nameof(UpdateMauiRippleDrawableBackground), BindingFlags.Static | BindingFlags.NonPublic); 47 | 48 | updateMauiRippleDrawableBackgroundMethod?.Invoke(null, [platformView, background, stroke, getEmptyBackgroundColor, getDefaultRippleColor, beforeSet]); 49 | } 50 | 51 | 52 | static MethodInfo? getStrokePropertiesMethod; 53 | 54 | internal static (int Thickness, ColorStateList Color, int Radius) GetStrokeProperties(this IButtonStroke button, Context context, bool defaultButtonLogic) 55 | { 56 | getStrokePropertiesMethod 57 | ??= MauiRippleDrawableExtensionsType?.GetMethod(nameof(GetStrokeProperties), BindingFlags.Static | BindingFlags.NonPublic); 58 | 59 | if (getStrokePropertiesMethod is not null) 60 | { 61 | var r = getStrokePropertiesMethod.Invoke(null, [button, context, defaultButtonLogic]); 62 | if (r is not null) 63 | return ((int Thickness, ColorStateList Color, int Radius))r; 64 | } 65 | return default; 66 | } 67 | } -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Tizen/PlatformClass1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Maui.ButtonContentView 4 | { 5 | // All the code in this file is only included on Tizen. 6 | public class PlatformClass1 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Windows/ContentButtonExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Platform; 2 | using Microsoft.UI.Xaml; 3 | using WButton = Microsoft.UI.Xaml.Controls.Button; 4 | 5 | namespace MauiContentButton; 6 | 7 | public static class ContentButtonExtensions 8 | { 9 | // The built in extension method expects IButton to apply the correct resource key changes 10 | // however we don't use IButton here to avoid the Text and Image related properties 11 | // So we need to manually do this update: 12 | 13 | public static void UpdateContentButtonBackground(this WButton platformButton, IContentButton button) 14 | { 15 | var brush = button.Background?.ToPlatform(); 16 | 17 | if (brush is null) 18 | platformButton.Resources.RemoveKeys(BackgroundResourceKeys); 19 | else 20 | platformButton.Resources.SetValueForAllKey(BackgroundResourceKeys, brush); 21 | 22 | RefreshThemeResources(platformButton); 23 | } 24 | 25 | internal static void RefreshThemeResources(FrameworkElement nativeView) 26 | { 27 | var previous = nativeView.RequestedTheme; 28 | 29 | // Workaround for https://github.com/dotnet/maui/issues/7820 30 | nativeView.RequestedTheme = nativeView.ActualTheme switch 31 | { 32 | ElementTheme.Dark => ElementTheme.Light, 33 | _ => ElementTheme.Dark 34 | }; 35 | 36 | nativeView.RequestedTheme = previous; 37 | } 38 | 39 | static readonly string[] BackgroundResourceKeys = 40 | { 41 | "ButtonBackground", 42 | "ButtonBackgroundPointerOver", 43 | "ButtonBackgroundPressed", 44 | "ButtonBackgroundDisabled", 45 | }; 46 | 47 | internal static void RemoveKeys(this Microsoft.UI.Xaml.ResourceDictionary resources, IEnumerable keys) 48 | { 49 | foreach (string key in keys) 50 | { 51 | resources.Remove(key); 52 | } 53 | } 54 | 55 | internal static void SetValueForAllKey(this Microsoft.UI.Xaml.ResourceDictionary resources, IEnumerable keys, object? value) 56 | { 57 | foreach (string key in keys) 58 | { 59 | resources[key] = value; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Windows/ContentButtonHandler.windows.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Handlers; 2 | using Microsoft.Maui.Platform; 3 | using Microsoft.UI.Xaml.Input; 4 | using Microsoft.UI.Xaml; 5 | using WVerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment; 6 | using WHorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment; 7 | 8 | namespace MauiContentButton; 9 | 10 | public partial class ContentButtonHandler : ViewHandler 11 | { 12 | PointerEventHandler? _pointerPressedHandler; 13 | PointerEventHandler? _pointerReleasedHandler; 14 | 15 | protected override MauiContentButton CreatePlatformView() 16 | { 17 | if (VirtualView == null) 18 | { 19 | throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a LayoutView"); 20 | } 21 | 22 | var button = new MauiContentButton() 23 | { 24 | VerticalAlignment = WVerticalAlignment.Stretch, 25 | HorizontalAlignment = WHorizontalAlignment.Stretch, 26 | Content = new MauiContentButtonContent 27 | { 28 | Margin = new Microsoft.UI.Xaml.Thickness(0), 29 | //CrossPlatformLayout = VirtualView 30 | }, 31 | Padding = new Microsoft.UI.Xaml.Thickness(0) 32 | }; 33 | 34 | return button; 35 | } 36 | 37 | protected override void ConnectHandler(MauiContentButton platformView) 38 | { 39 | _pointerPressedHandler = new PointerEventHandler(OnPointerPressed); 40 | _pointerReleasedHandler = new PointerEventHandler(OnPointerReleased); 41 | 42 | platformView.Click += OnClick; 43 | platformView.AddHandler(UIElement.PointerPressedEvent, _pointerPressedHandler, true); 44 | platformView.AddHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler, true); 45 | 46 | base.ConnectHandler(platformView); 47 | } 48 | 49 | 50 | protected override void DisconnectHandler(MauiContentButton platformView) 51 | { 52 | if (platformView.Content is ContentPanel buttonContentPanel) 53 | { 54 | buttonContentPanel.CrossPlatformLayout = null; 55 | buttonContentPanel.Children?.Clear(); 56 | } 57 | 58 | platformView.Click -= OnClick; 59 | platformView.RemoveHandler(UIElement.PointerPressedEvent, _pointerPressedHandler); 60 | platformView.RemoveHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler); 61 | 62 | _pointerPressedHandler = null; 63 | _pointerReleasedHandler = null; 64 | 65 | base.DisconnectHandler(platformView); 66 | } 67 | 68 | public static void MapContent(IContentButtonHandler handler, IContentButton view) 69 | { 70 | _ = handler.PlatformView ?? throw new InvalidOperationException($"{nameof(PlatformView)} should have been set by base class."); 71 | _ = handler.VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); 72 | _ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class."); 73 | 74 | 75 | if (handler.PlatformView.Content is MauiContentButtonContent buttonContentPanel) 76 | { 77 | buttonContentPanel.Children.Clear(); 78 | 79 | if (handler.VirtualView.PresentedContent is IView presentedView) 80 | { 81 | var plat = presentedView.ToPlatform(handler.MauiContext); 82 | buttonContentPanel.Children.Add(plat); 83 | } 84 | } 85 | } 86 | 87 | // This is a Windows-specific mapping 88 | public static void MapBackground(IContentButtonHandler handler, IContentButton button) 89 | { 90 | handler.PlatformView.UpdateContentButtonBackground(button); 91 | } 92 | 93 | public static void MapStrokeColor(IContentButtonHandler handler, IButtonStroke buttonStroke) 94 | { 95 | handler.PlatformView?.UpdateStrokeColor(buttonStroke); 96 | } 97 | 98 | public static void MapStrokeThickness(IContentButtonHandler handler, IButtonStroke buttonStroke) 99 | { 100 | handler.PlatformView?.UpdateStrokeThickness(buttonStroke); 101 | } 102 | 103 | public static void MapCornerRadius(IContentButtonHandler handler, IButtonStroke buttonStroke) 104 | { 105 | handler.PlatformView?.UpdateCornerRadius(buttonStroke); 106 | } 107 | 108 | public static void MapPadding(IContentButtonHandler handler, IPadding padding) 109 | { 110 | handler.PlatformView?.UpdatePadding(padding, new Microsoft.UI.Xaml.Thickness(0)); 111 | } 112 | 113 | void OnClick(object sender, RoutedEventArgs e) 114 | { 115 | VirtualView?.Clicked(); 116 | } 117 | 118 | void OnPointerPressed(object sender, PointerRoutedEventArgs e) 119 | { 120 | VirtualView?.Pressed(); 121 | } 122 | 123 | void OnPointerReleased(object sender, PointerRoutedEventArgs e) 124 | { 125 | VirtualView?.Released(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Windows/MauiContentButton.windows.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Platform; 2 | using WButton = Microsoft.Maui.Platform.MauiButton; 3 | using WVerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment; 4 | using WHorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment; 5 | using Microsoft.UI.Xaml.Automation.Peers; 6 | 7 | namespace MauiContentButton; 8 | 9 | public class MauiContentButton : WButton 10 | { 11 | public MauiContentButton() : base() 12 | { 13 | VerticalAlignment = WVerticalAlignment.Stretch; 14 | HorizontalAlignment = WHorizontalAlignment.Stretch; 15 | Padding = new Microsoft.UI.Xaml.Thickness(0); 16 | } 17 | 18 | protected override AutomationPeer OnCreateAutomationPeer() 19 | { 20 | return new MauiButtonAutomationPeer(this); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Maui.ContentButton/Platforms/Windows/MauiContentButtonContent.windows.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Platform; 2 | using WVerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment; 3 | using WHorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment; 4 | using WThickness = Microsoft.UI.Xaml.Thickness; 5 | using WSize = Windows.Foundation.Size; 6 | using WRect = Windows.Foundation.Rect; 7 | 8 | namespace MauiContentButton; 9 | 10 | public class MauiContentButtonContent : MauiPanel 11 | { 12 | public MauiContentButtonContent() : base() 13 | { 14 | VerticalAlignment = WVerticalAlignment.Stretch; 15 | HorizontalAlignment = WHorizontalAlignment.Stretch; 16 | Visibility = Microsoft.UI.Xaml.Visibility.Visible; 17 | Margin = new WThickness(0); 18 | } 19 | 20 | protected override WSize MeasureOverride(WSize availableSize) 21 | { 22 | double measuredHeight = 0; 23 | double measuredWidth = 0; 24 | 25 | foreach (var c in Children) 26 | { 27 | c.Measure(availableSize); 28 | measuredHeight = Math.Max(measuredHeight, c.DesiredSize.Height); 29 | measuredWidth = Math.Max(measuredWidth, c.DesiredSize.Width); 30 | } 31 | 32 | if (!double.IsInfinity(availableSize.Width) && HorizontalAlignment == WHorizontalAlignment.Stretch) 33 | { 34 | measuredWidth = Math.Max(measuredWidth, availableSize.Width); 35 | } 36 | 37 | if (!double.IsInfinity(availableSize.Height) && VerticalAlignment == WVerticalAlignment.Stretch) 38 | { 39 | measuredHeight = Math.Max(measuredHeight, availableSize.Height); 40 | } 41 | 42 | return new WSize(measuredWidth, measuredHeight); 43 | } 44 | 45 | protected override WSize ArrangeOverride(WSize finalSize) 46 | { 47 | foreach (var c in Children) 48 | c.Arrange(new WRect(0, 0, finalSize.Width, finalSize.Height)); 49 | 50 | return new WSize(finalSize.Width, finalSize.Height); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Maui.ContentButton 2 | Button that can take any content inside of it while still acting like a native button 3 | 4 | ![NuGet Version](https://img.shields.io/nuget/v/Plugin.Maui.ContentButton?style=flat&logo=nuget&logoColor=ffffff&color=0b6cff) 5 | 6 | 7 | 8 | | Android | Windows | iOS | 9 | |---------|---------|-----| 10 | | ![Maui ContentButton Android](https://github.com/user-attachments/assets/1a9a8872-6901-411d-9e9f-c462f0fbd8d8) | ![Maui ContentButton Windows](https://github.com/user-attachments/assets/de9c5bef-d2c6-491e-a9f8-9d3f0f5bd773) | ![Maui ContentButton iOS](https://github.com/user-attachments/assets/46a9508c-43e8-4d68-bfa1-d4724bd92689) | 11 | 12 | 13 | ## Platform Support 14 | 15 | ### Windows 16 | Windows allows content nested in the `Button` control, so that's what we are using here. You have a real genuine native button with this control on Windows. 17 | 18 | ### iOS / MacCatalyst 19 | Apple's platforms have a `UIButton` which also allows adding nested content (subviews). Just like with windows, we are using a real native `UIButton` to implement this control. 20 | 21 | ### Android 22 | Android is the trickiest, since its `Button` (and `MaterialButton`) derive from `View` which does _not_ allow directly nested content. Luckily Android is pretty flexible about making arbitrary views (and `ViewGroup`s) act like a button. In this case we use `MaterialCardView` to help with the ripple effect, shape, etc and then add click/touch listeners to make it behave like a button. Android seems to consider this a real authentic button as far as the system and accessibility interations are concerned, it even plays the system 'click' sound when you press it! 23 | 24 | ## Usage 25 | 26 | Add `.AddMauiContentButtonHandler()` to your app builder in your MauiProgram.cs: 27 | 28 | ```csharp 29 | builder 30 | .UseMauiApp() 31 | // Register the handler 32 | .AddMauiContentButtonHandler() 33 | .ConfigureFonts(fonts => 34 | { 35 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 36 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); 37 | }); 38 | ``` 39 | 40 | Import the xml namespace in the XAML file you would like to use the Content Button in: 41 | `xmlns:mcb="http://schemas.microsoft.com/dotnet/2024/maui/contentbutton"` 42 | 43 | Use the button with whatever content you wish! 44 | 45 | ```xml 46 | 50 | 51 | 55 | 89 | 90 | ``` 91 | 92 | 93 | You may want to add a style to your app's `Resources/Styles/Styles.xaml` to make the defaults more like the normal `Button` 94 | (remember to add the `xmlns:mcb="http://schemas.microsoft.com/dotnet/2024/maui/contentbutton"` namespace to your `` element): 95 | ```xml 96 | 115 | ``` 116 | 117 | ## Known Issues 118 | - Due to some recent changes in MAUI itself, this currently requires .NET MAUI 8.0.90 (SR9) or newer 119 | -------------------------------------------------------------------------------- /Sample/App.xaml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Sample 2 | { 3 | public partial class App : Application 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | 9 | MainPage = new AppShell(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sample/AppShell.xaml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Sample/AppShell.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Sample 2 | { 3 | public partial class AppShell : Shell 4 | { 5 | public AppShell() 6 | { 7 | InitializeComponent(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sample/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 11 | 16 | 17 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Sample/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Sample 2 | { 3 | public partial class MainPage : ContentPage 4 | { 5 | int count = 0; 6 | 7 | public MainPage() 8 | { 9 | InitializeComponent(); 10 | } 11 | 12 | private void OnCounterClicked(object sender, EventArgs e) 13 | { 14 | count++; 15 | 16 | 17 | if (count == 1) 18 | labelCounter.Text = $"Clicked {count} time"; 19 | else 20 | labelCounter.Text = $"Clicked {count} times"; 21 | 22 | ellipseState.Fill = (count % 2 == 0 ? App.Current.Resources["Tertiary"] : App.Current.Resources["Secondary"]) as Color; 23 | //SemanticScreenReader.Announce(CounterBtn.Text); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Sample/MauiProgram.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using MauiContentButton; 3 | 4 | namespace Sample 5 | { 6 | public static class MauiProgram 7 | { 8 | public static MauiApp CreateMauiApp() 9 | { 10 | var builder = MauiApp.CreateBuilder(); 11 | builder 12 | .UseMauiApp() 13 | .AddMauiContentButtonHandler() 14 | .ConfigureFonts(fonts => 15 | { 16 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 17 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); 18 | }); 19 | 20 | #if DEBUG 21 | builder.Logging.AddDebug(); 22 | #endif 23 | 24 | return builder.Build(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sample/Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sample/Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace Sample 6 | { 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sample/Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace Sample 5 | { 6 | [Application] 7 | public class MainApplication : MauiApplication 8 | { 9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 10 | : base(handle, ownership) 11 | { 12 | } 13 | 14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sample/Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /Sample/Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace Sample 4 | { 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sample/Platforms/MacCatalyst/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | com.apple.security.app-sandbox 8 | 9 | 10 | com.apple.security.network.client 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sample/Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | UIDeviceFamily 15 | 16 | 2 17 | 18 | UIRequiredDeviceCapabilities 19 | 20 | arm64 21 | 22 | UISupportedInterfaceOrientations 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationLandscapeLeft 26 | UIInterfaceOrientationLandscapeRight 27 | 28 | UISupportedInterfaceOrientations~ipad 29 | 30 | UIInterfaceOrientationPortrait 31 | UIInterfaceOrientationPortraitUpsideDown 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | XSAppIconAssets 36 | Assets.xcassets/appicon.appiconset 37 | 38 | 39 | -------------------------------------------------------------------------------- /Sample/Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace Sample 5 | { 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sample/Platforms/Tizen/Main.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui; 2 | using Microsoft.Maui.Hosting; 3 | using System; 4 | 5 | namespace Sample 6 | { 7 | internal class Program : MauiApplication 8 | { 9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 10 | 11 | static void Main(string[] args) 12 | { 13 | var app = new Program(); 14 | app.Run(args); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sample/Platforms/Tizen/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | maui-appicon-placeholder 7 | 8 | 9 | 10 | 11 | http://tizen.org/privilege/internet 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sample/Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /Sample/Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace Sample.WinUI 7 | { 8 | /// 9 | /// Provides application-specific behavior to supplement the default Application class. 10 | /// 11 | public partial class App : MauiWinUIApplication 12 | { 13 | /// 14 | /// Initializes the singleton application object. This is the first line of authored code 15 | /// executed, and as such is the logical equivalent of main() or WinMain(). 16 | /// 17 | public App() 18 | { 19 | this.InitializeComponent(); 20 | } 21 | 22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Sample/Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | $placeholder$ 15 | User Name 16 | $placeholder$.png 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Sample/Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Sample/Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace Sample 4 | { 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sample/Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationLandscapeLeft 20 | UIInterfaceOrientationLandscapeRight 21 | 22 | UISupportedInterfaceOrientations~ipad 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationPortraitUpsideDown 26 | UIInterfaceOrientationLandscapeLeft 27 | UIInterfaceOrientationLandscapeRight 28 | 29 | XSAppIconAssets 30 | Assets.xcassets/appicon.appiconset 31 | 32 | 33 | -------------------------------------------------------------------------------- /Sample/Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace Sample 5 | { 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sample/Platforms/iOS/Resources/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | NSPrivacyAccessedAPITypes 14 | 15 | 16 | NSPrivacyAccessedAPIType 17 | NSPrivacyAccessedAPICategoryFileTimestamp 18 | NSPrivacyAccessedAPITypeReasons 19 | 20 | C617.1 21 | 22 | 23 | 24 | NSPrivacyAccessedAPIType 25 | NSPrivacyAccessedAPICategorySystemBootTime 26 | NSPrivacyAccessedAPITypeReasons 27 | 28 | 35F9.1 29 | 30 | 31 | 32 | NSPrivacyAccessedAPIType 33 | NSPrivacyAccessedAPICategoryDiskSpace 34 | NSPrivacyAccessedAPITypeReasons 35 | 36 | E174.1 37 | 38 | 39 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Sample/Resources/AppIcon/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Sample/Resources/AppIcon/appiconfg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sample/Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Redth/Maui.ContentButton/9c3ee8c7f70d330013a76e8bed8c947ed68d6f89/Sample/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /Sample/Resources/Fonts/OpenSans-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Redth/Maui.ContentButton/9c3ee8c7f70d330013a76e8bed8c947ed68d6f89/Sample/Resources/Fonts/OpenSans-Semibold.ttf -------------------------------------------------------------------------------- /Sample/Resources/Images/dotnet_bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Redth/Maui.ContentButton/9c3ee8c7f70d330013a76e8bed8c947ed68d6f89/Sample/Resources/Images/dotnet_bot.png -------------------------------------------------------------------------------- /Sample/Resources/Raw/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories). Deployment of the asset to your application 3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. 4 | 5 | 6 | 7 | These files will be deployed with your package and will be accessible using Essentials: 8 | 9 | async Task LoadMauiAsset() 10 | { 11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); 12 | using var reader = new StreamReader(stream); 13 | 14 | var contents = reader.ReadToEnd(); 15 | } 16 | -------------------------------------------------------------------------------- /Sample/Resources/Splash/splash.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sample/Resources/Styles/Colors.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 8 | 9 | #512BD4 10 | #ac99ea 11 | #242424 12 | #DFD8F7 13 | #9880e5 14 | #2B0B98 15 | 16 | White 17 | Black 18 | #D600AA 19 | #190649 20 | #1f1f1f 21 | 22 | #E1E1E1 23 | #C8C8C8 24 | #ACACAC 25 | #919191 26 | #6E6E6E 27 | #404040 28 | #212121 29 | #141414 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Sample/Resources/Styles/Styles.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 7 | 8 | 11 | 12 | 16 | 17 | 22 | 23 | 26 | 27 | 52 | 53 | 72 | 73 | 90 | 91 | 111 | 112 | 133 | 134 | 155 | 156 | 162 | 163 | 184 | 185 | 203 | 204 | 207 | 208 | 214 | 215 | 221 | 222 | 226 | 227 | 249 | 250 | 265 | 266 | 286 | 287 | 290 | 291 | 314 | 315 | 335 | 336 | 342 | 343 | 362 | 363 | 366 | 367 | 395 | 396 | 416 | 417 | 421 | 422 | 434 | 435 | 440 | 441 | 447 | 448 | 449 | -------------------------------------------------------------------------------- /Sample/Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0-android;net8.0-ios;net8.0-maccatalyst 5 | $(TargetFrameworks);net8.0-windows10.0.19041.0 6 | 7 | 8 | 9 | 14 | 15 | 16 | Exe 17 | Sample 18 | true 19 | true 20 | enable 21 | enable 22 | 23 | 24 | Sample 25 | 26 | 27 | com.companyname.sample 28 | 29 | 30 | 1.0 31 | 1 32 | 33 | 11.0 34 | 13.1 35 | 21.0 36 | 10.0.17763.0 37 | 10.0.17763.0 38 | 6.5 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.400", 4 | "rollForward": "latestMinor", 5 | "allowPrerelease": false 6 | } 7 | } --------------------------------------------------------------------------------